问答详情
源自:5-5 练习

LISTAGG、WM_CONCAT

方法一:

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;


提问者:慕哥6564234 2019-10-05 10:19

个回答