慕哥6564234
2019-10-05 10:19
方法一:
SELECT CID, LISTAGG(SNAME, ',') WITHIN GROUP(ORDER BY R)
FROM (SELECT ROWNUM R, A.*
FROM (SELECT C.CI_ID CID,
S.STU_NAME SNAME,
INSTR(C.STU_IDS, S.STU_ID) SEQ
FROM PM_CI C, PM_STU S
WHERE INSTR(C.STU_IDS, S.STU_ID) <> 0
ORDER BY CI_ID, SEQ) A) T
GROUP BY T.CID;
方法二:
SELECT T.CID, MAX(SNAMES)
FROM (SELECT B.CID,
WM_CONCAT(B.SNAME) OVER(PARTITION BY B.CID ORDER BY B.SEQ) SNAMES
FROM (SELECT ROWNUM R, A.*
FROM (SELECT C.CI_ID CID,
S.STU_NAME SNAME,
INSTR(C.STU_IDS, S.STU_ID) SEQ
FROM PM_CI C, PM_STU S
WHERE INSTR(C.STU_IDS, S.STU_ID) <> 0
ORDER BY CI_ID, SEQ) A) B) T
GROUP BY T.CID;
Oracle高级查询
62862 学习 · 144 问题
相似问题