select d.gubun, d.sub_gubun, max( d.geum1 ) As geum1, sum( d.geum1 ) as tgeum, count(d.*)as cnt
from(
select '111' As gubun, 'a' as sub_gubun, 1000 As geum1
union all
select '111' As gubun, 'b' as sub_gubun, 1700 As geum1
union all
select '222' As gubun, 'b' as sub_gubun, 1500 As geum1
)d
group by d.gubun, d.sub_gubun
order by d.gubun, d.sub_gubun
결과값은:
"111";"a";1000;1000;1
"111";"b";1700;1700;1
"222";"b";1500;1500;1
이렇게 나오는데요,
"111";"a";1000;2000;2
"111";"b";1700;2700;2
"222";"b";1500;1500;1
이렇게 나올수는 없나요?
네번째 항목은 세번째의 합, 다섯번째 항목은 d.gubun의 row수...
이렇게 저렇게 해봐도, 쿼리작성 능력부족이네요. T.T
|