Created
May 9, 2018 11:59
-
-
Save nurettin/c2caedc8a0759686937dc9dfb2e8019c to your computer and use it in GitHub Desktop.
group rows by pilot row, show line numbers and line count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
i | |
, c | |
, g | |
, gi | |
, sum(1) over (partition by g) gn | |
from ( | |
select | |
i | |
, c | |
, g | |
, row_number() over(partition by g order by i) gi | |
from ( | |
select | |
i | |
, c | |
, sum(case c when 'a' then 1 else 0 end) over (order by i) g | |
from ( | |
select 1 i, 'a' c union all | |
select 2, 'b' union all | |
select 3, 'c' union all | |
select 4, 'a' union all | |
select 5, 'b' union all | |
select 6, 'a' union all | |
select 7, 'b' union all | |
select 8, 'c' union all | |
select 9, 'd' | |
) t | |
) t | |
) t | |
order by i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment