clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 648391 fiddles created (15115 in the last week).

CREATE TABLE tab(a,b,c) AS values (1, 1, null), (2, null, null), (3, null, null), (4, null, 1), (6, null, null), (7, null, null), (8, 1, null), (9, null, 1), (10, 1,null), (11,null,1), (12,1,1);
11 rows affected
 hidden batch(es)


SELECT a,b,c, CASE WHEN b = 1 AND c= 1 THEN 1 WHEN b =1 THEN COUNT(*) OVER(PARTITION BY s)+1 END AS cnt FROM (SELECT *, SUM(COALESCE(b,0)+COALESCE(c,0)) OVER(ORDER BY a) s FROM tab) s
a b c cnt
1 1 4
2
3
4 1
6
7
8 1 2
9 1
10 1 2
11 1
12 1 1 1
 hidden batch(es)