LISTAGG、WM_CONCAT

来源:5-5 练习

慕哥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;


写回答 关注

1回答

Oracle高级查询

数据库开发中应用广泛的高级查询,本教程通过大量的案例详细讲解

62862 学习 · 144 问题

查看课程

相似问题