İşte a_horse_with_no_name'in mükemmel +1 cevabının bir gösterimi .
SQL> WITH Data AS (
2 SELECT level, DECODE(Level,3,NULL,1) A
3 , DECODE(level,2,NULL,4,2,1) B
4 FROM dual connect by level <=5
5 )
6 SELECT A, B, count(*) FROM Data GROUP BY B, A;
A B COUNT(*)
- - ----------
1 1 2
1 1
1 2 1
1 1
SQL> WITH Data AS (
2 SELECT level, DECODE(Level,3,NULL,1) A
3 , DECODE(level,2,NULL,4,2,1) B
4 FROM dual connect by level <=5
5 )
6 SELECT COALESCE(B, A) X, count(*) FROM Data GROUP BY COALESCE(B, A);
X COUNT(*)
- ----------
1 4
2 1