比如:
表t1 表t2
A B C D
3 2 3 6
3 4 7 8
通过类似select C,D,xxxxxx F from (select B from t1 where A=t2.c) t3,t2
让结果变为:
C D F
3 6 2,4
要怎么做?
------解决方案--------------------
SQL> select deptno,wm_concat(ename) bb from emp group by deptno;
DEPTNO BB
---------- --------------------------------------------------
10 CLARK,KING,MILLER
20 SMITH,FORD,ADAMS,SCOTT,JONES
30 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD
------解决方案--------------------
with t1 as
(select 3 A, 2 B FROM DUAL UNION ALL SELECT 3 A, 4 B FROM DUAL),
T2 AS
(select 3 C, 6 D FROM DUAL UNION ALL select 7 C, 8 D FROM DUAL)
SELECT C, D, MAX(F)F
FROM (SELECT T2.C, T2.D, TO_CHAR(wm_concat(T1.B) OVER(ORDER BY T1.B)) F
FROM T1, T2
WHERE T1.A = T2.C)
GROUP BY C, D;
------解决方案--------------------
SELECT C,D,WM_CONCAT(A) FROM (Select t2.C,T2.D ,T1.A FROM T1,T2 WHERE T1.A = T2.C) T3 GROUP BY C,D