Skip to content
Advertisement

PARTITION rows by status

I have a query which fetches result by status partition as rank. but I need a result as given below.

Please help in getting the desired result. Thanks in advance. Using #standardsql

Advertisement

Answer

This is a gaps-and-islands problem. The difference of row numbers should do what you want to identify the groups:

It is a little big cumbersome to explain why the difference of row numbers identifies adjacent rows with the same value. If you look at the results of the subquery, though, you should see how this works.

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