by 커피요쿠르트d [SQL Query] oracle rollup round [2013.04.16 20:01:40]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | with tbl1 as ( select 'aa' code, 4.5 value from dual union all select 'aa' code, 4.5 value from dual union all select 'aa' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual ) select code, round( sum (value)) from tbl1 group by rollup (code) ; with tbl2 as ( select 'aa' code, 4.5 value from dual union all select 'aa' code, 4.5 value from dual union all select 'aa' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual union all select 'bb' code, 4.5 value from dual ) select code, sum (round(value)) from tbl2 group by rollup (code) ; |
1 2 3 4 5 | with result as ( select 'aa' code, 14 value from dual union all select 'bb' code, 14 value from dual union all select '' code, 28 value from dual ) select * from result |