SQLize Online / PHPize Online  /  SQLtest Online

Share      Blog   Popular
Copy Format Clear
with u(el) as ( select unnest('{1,1,1,1,0,0,1,1,0,0}'::int[]) ), un as ( select row_number() over() rn, el from u ), ch as (select *, case when el = lag(el) over (order by rn) then 0 else 1 end ch from un), sm as ( select *, sum(ch) over (order by rn) sm from ch ) select min(rn) || ',' || max(rn) res from sm where el = 1 group by el, sm order by res;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear