结合Sql Developer中的类似字段?

问题描述 投票:0回答:1

我目前有一个查询,如下所示:

SELECT c.Course_No
       , c.Description
       ,  e.Section_Id
       , COUNT(e.Section_ID) AS enrollment
FROM Enrollment e JOIN
     Section s
     ON e.Section_Id = s.Section_Id JOIN
     Course c
     ON s.Course_No = c.Course_No
Group by c.Course_No, c.Description, e.Section_Id
ORDER BY c.Course_No

它工作正常,这里是结果的片段:

COURSE_NO              DESCRIPTION                                        SECTION_ID             ENROLLMENT             
---------------------- -------------------------------------------------- ---------------------- ---------------------- 
10                     Technology Concepts                                80                     1                      
20                     Intro to Information Systems                       81                     3                      
20                     Intro to Information Systems                       82                     2                      
20                     Intro to Information Systems                       83                     2                      
20                     Intro to Information Systems                       84                     2           

我的问题是你们:有没有办法结合具有相同课程描述和不同sectionID的字段?我希望将所有领域合并,但我不确定如何这样做。

添加了提示和预期结果:生成一个字母列表,其中包含在第90节的期末考试中得分高于平均水平的学生的姓氏和期末考试成绩(FI)。

LAST_NAME                 NUMERIC_GRADE
------------------------- -------------
Da Silva                             92
Lopez                                91 
sql oracle combinations
1个回答
1
投票

我想你想要这样的东西:

SELECT c.Course_No, c.Description, 
       LISTAGG(e.Section_Id, ',') WITHIN GROUP (ORDER BY e.Section_Id) as sections,
       COUNT(*) AS enrollment
FROM Enrollment e JOIN
     Section s
     ON e.Section_Id = s.Section_Id JOIN
     Course c
     ON s.Course_No = c.Course_No
Group by c.Course_No, c.Description
ORDER BY c.Course_No
© www.soinside.com 2019 - 2024. All rights reserved.