Skip to content
Advertisement

count sequence of particular value

I have a snowflake table like this:

and I want to count sequence of 1 on column “flag” group by artc and locl, order by date_col

The desire output is:

I was trying things like:

but it doesn’t start fresh count on group changes. Thanks for any help!

Advertisement

Answer

Assign each group of “1”s a grouping by counting the number of “0”s before them. Then filter and aggregate:

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