Skip to content
Advertisement

query with sql max function

table view with 4 records

Would the following query work if I wanted to select the 2nd and 3rd records?

Advertisement

Answer

As your date values are not in well formatted, you need to first convert your values into DATE and then apply other logic. Please check my updated script now-

Issues:

  1. You value in completion_date column is string. as a result, MAX was returning the value considering STRING, not DATE.
  2. You have no YEAR value in the completion_date column. As a result, I just added ‘2020’ to the value so that DATE value generated properly. At the end, the added year has no impact on the output. And this is considering all DTAEs are from the single (any) YEAR only.
  3. But if you have YEAR value in some other column, avoid adding static ‘2020’ and use the value from that column

Check DEMO HERE

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