ROLLUP 구문 사용시 소계가 그룹의 하단에 나오는데 그룹의 상단에 나오도록 하고 싶습니다.
방법이 있을까요?
by 마농
[2016.08.25 18:15:11]
ORDER BY 에 NULS FIRST, GROUPING() 등을 적절히 사용하시면 됩니다.
by jkson
[2016.08.25 18:25:18]
with t as
(select 'A' code, '1' id from dual
union all
select 'B', '2' from dual
)
select decode(1,grouping(code),'총계',grouping(id),code||' 소계',code) codenm
, id
, count(1) cnt
from t
group by rollup(code, id)
order by code, grouping(id) desc
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.