SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with d as ( select 1 n_id, 1 id union all -- 1 select 5 n_id, 2 id union all -- 2 select 5 n_id, 3 id union all -- 2 select 3 n_id, 4 id union all -- 3 select 3 n_id, 5 id union all -- 3 select 3 n_id, 6 id union all -- 3 select 5 n_id, 7 id union all -- 4 select 5 n_id, 8 id ), c as ( select n_id, id, case when n_id = lag(n_id) over (order by id) then 0 else 1 end c from d ) select n_id, id, sum(c) over (order by id) from c order by id;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear