I want to assign row_number() to missing values as well. I know that row_number will assign sequence to the non-missing values. How can we approach this problem?
Code Snippet
SELECT id, date,sum(purchase) as purch,
row_number() over(partition by id order by date desc) as rown
FROM table
where
date in (current_date(),current_date()-1,current_date()-2)
OR
date between current_date()-364 and current_date()-365
group by id,date
order by date desc
I want to use the values of sum(purchase) for particular dates, so, I want the row_number for each dates even no purchase has happened at that particular day(value could get replace with NULL).
output should look like-
row_number purchase date
1 23 current_date
2 24 current_date-1
3 null current_date-2(let's say this is our missing date data)
4 23 current_date-364
5 null current_date-365(let's say this date is mising in our data)