Skip to content
Advertisement

Query Hierarchical Queries

I wanted to profile my data set to find the data discrepancies.

My sample date set:

I would like to find out how many of those IDs have a result status that is older than current. The order of the status sequence should be NEW-PROCESS-COMPLETE. So I want report all IDs where the most recent status has reversed to an earlier status.

Advertisement

Answer

You can use the LAG() function to find the offending rows, as in:

Note: I assume you need to compare only between rows of the same ID.

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