Skip to content
Advertisement

How to find second and max date and compare these two

so I need to find the highest and second highest date from every SKU(number) and compare these 2 dates and see if there is a 3 months difference.

down below is my code I already found the second highest date but I can’t seem to make it work with a highest date in combination anyone for the rescue ?

code :

Advertisement

Answer

I’m going to sketch the answer I mean rather than try to make it perfect with your query. This uses three CTEs. X0 assigns the RN value. X1 picks out where RN=1 and X2 picks out where RN=2. Then you join X1 and X2, and do your calculation.

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