Assume I have an End Date in a table
End Date
1/1/2018
5/1/2017
6/1/2017
12/31/2020
I need to compare each row's date with all previous rows date and set a flag or value if the current row date is less than any of the previous rows dates
In this case, row number 3 is greater than row number 2 but it is less than row number 1. Also row number 2 is less than row number 1. Row number 4 is greater than all the other rows
So the result should be something like this
End Date Flag
1/1/2018 NULL ( Since no previous values to compare)
5/1/2017 Y
6/1/2017 Y
12/31/2020 N
I tried ROWNUMBER and LAG, I was only able to compare just the previous row. Not ALL the previous rows in the table. Please advise