create table t2 as
with t as (select level-1 l from dual connect by level<=10),
t1 as(select t.l a,t1.l b,t2.l c,t3.l d from t,t t1,t t2,t t3,t t4,t t5,t t6)
-- select count(*),sum(a+b+c+d) from t1
SELECT A,B,C,D,
SUM(CASE
WHEN A>0 THEN 0
WHEN B>0 THEN 1
WHEN C=0 THEN 2
WHEN D=9 THEN 4
END) Q
FROM T1
GROUP BY A,B,C,D
;
select mod(level,2) id from dual connect by level<10