by 가나다아아 [Oracle 기초] select oracle 9i sys_connect_by_path partition by [2017.12.11 16:38:26]
(oracle 9i)
SELECT A.A1,
A.A2,
A.A3,
A.A4,
A.A5,
A.A6,
A.A7,
SUM (A.A8) AS A8,
COUNT (A.A9) A9,
COUNT (DISTINCT A.A10) A10
FROM A A, B B
WHERE 1 = 1 AND A.A10 = B.B10 AND A.A1 = '20171211'
GROUP BY A.A1,
A.A2,
A.A3,
A.A4,
A.A5,
A.A6,
A.A7;
A1 ~ A6까진 모두 같고 A8 ~ A10은 SUM이 되는건데 A7컬럼이 A,B로 나와서(C,D 더 추가될수도있음)
로우가 두줄로 나왔다면 한줄로 합치면서 A7컬럼의 내용을 " A/B " 처럼 합쳐주고싶습니다.
이런경우에 어떤식으로 쿼리를 짜야할지 궁금합니다 도와주세요!!
SELECT a.a1 , a.a2 , a.a3 , a.a4 , a.a5 , a.a6 , SUBSTR(XMLAgg(XMLElement(x, '/', a.a7) ORDER BY a.a7).Extract('//text()'), 2) a7 , SUM(a.a8) a8 , COUNT(a.a9) a9 , COUNT(DISTINCT a.a10) a10 FROM a a , b b WHERE 1 = 1 AND a.a10 = b.b10 AND a.a1 = '20171211' GROUP BY a.a1, a.a2, a.a3, a.a4, a.a5, a.a6 ORDER BY a.a1, a.a2, a.a3, a.a4, a.a5, a.a6 ; -- http://gurubee.net/article/55512
SELECT a1 , a2 , a3 , a4 , a5 , a6 , SUBSTR(XMLAgg(XMLElement(x, '/', a7) ORDER BY a7).Extract('//text()'), 2) a7 , SUM(a8) a8 , SUM(a9) a9 , a10 FROM (SELECT a.a1 , a.a2 , a.a3 , a.a4 , a.a5 , a.a6 , a.a7 , SUM(a.a8) a8 , COUNT(a.a9) a9 , COUNT(DISTINCT a.a10) OVER(PARTITION BY a.a1, a.a2, a.a3, a.a4, a.a5, a.a6) a10 FROM a a , b b WHERE 1 = 1 AND a.a10 = b.b10 AND a.a1 = '20171211' GROUP BY a.a1, a.a2, a.a3, a.a4, a.a5, a.a6, a.a7 ) GROUP BY a1, a2, a3, a4, a5, a6, a10 ORDER BY a1, a2, a3, a4, a5, a6 ;