奶奶的,直接decode还有问题,换grouping就可以了
WITH t AS
(SELECT 1 a,2 b,3 c,4 d,5 e,6 f,7g,8 h
FROM dual)
SELECT
decode(GROUPING(a),1,0,1) a,
decode(GROUPING(b),1,0,1) b,
decode(GROUPING(c),1,0,1) c,
decode(GROUPING(d),1,0,1) d,
decode(GROUPING(e),1,0,1) e,
decode(GROUPING(f),1,0,1) f,
decode(GROUPING(g),1,0,1) g,
decode(GROUPING(h),1,0,1) h
FROM t
GROUP BY CUBE(a,b,c,d,e,f,g,h);
A B C D E F G H
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 1
0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 1
0 0 0 0 0 1 1 0
0 0 0 0 0 1 1 1
=====================================
1 1 1 1 1 0 0 0
1 1 1 1 1 0 0 1
1 1 1 1 1 0 1 0
1 1 1 1 1 0 1 1
1 1 1 1 1 1 0 0
1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
256 rows selected
要id??查询的再套一层,rownum+1000