by 커피요쿠르트d [SQL Query] oracle rollup round [2013.04.16 20:01:40]
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) ;윗부분은 sum()을 하고 round() 처리를 한 것이구요 .
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