Skip to content
Advertisement

SQL+Fetch rows with latest date+Case when row_number()+Duplicates

I have a table with fields(id, date, product) with below sample data

I’m trying the case when row_number() over (partition by id order by date) = 1 then 1 else 0 end as flag, But for a particular distinct Id with min date, it is getting flag as 1, but I need to flag as for a particular Id & min date and product as 1 flag as shown in Expected_flag

Advertisement

Answer

You need dense_rank() instead :

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement