Skip to content
Advertisement

SQL Consecutive value meet certain threshold [closed]

I have a table like below.

Table A

The goal is to find consecutive rows which are <= 60

Desired results:

I have tried lead and lag function like other solution provided with no luck. Hope anyone may help here!

Advertisement

Answer

Would you try this? I’ve wrote it in BigQuery but you can understand the logic in it.

As @tim-biegeleisen metioned, the table should have ordering column, so I’ve added it with name idx.

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