Skip to content
Advertisement

SQL to find records with last 3 same status

I have the following tasks table:

I need to run a query that returns only the types which their last 3 tasks finished with status “FAILED”.

How can I do this? Should I use a window function?

Thanks

Advertisement

Answer

You can use aggregation and filtering after using row_number() to get the last three rows:

Actually, a slightly simpler method is:

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