Skip to content

Tag: sql

Prioritize one column over another

DB-Fiddle In the table above I have different campaigns with their corresponding quantities. The quantities are filled in different columns. Now, I want to get the latest available quantity for each campaign based on the following hierarchy: The result should look like this: What query do I need to achieve th…

How to save data after using With Clause?

I want to save the data I have after With Clause. Maybe saving into TEMP table or some other data set. WITH TASKLIST AS (SELECT * FROM IC_V_NEWSKUSTASKLIST WHERE MSTID IS NULL), RESULTS AS (SELECT *…

Find first occurance within a group of groups

I have a table with 5 columns. I want to find the % received of the last date and first occurance of date_rec. Output required: Answer In R, we can do slice after grouping by ‘Country’, ‘Flow’ The above assumes that the ‘Date’ are ordered (in the OP’s example it is al…