代码之家  ›  专栏  ›  技术社区  ›  Shivam Amin

需要帮助合并两个select语句的结果

  •  0
  • Shivam Amin  · 技术社区  · 8 年前

    我的第一个select语句是:

    SELECT cRefNum, cName,  cProgram || '-' || cCode || '-' || cSection as CourseDesc, cTimeStart, cTimeEnd, cDay, ct.cCampus, cBuildingSection || cRoom AS Room, cSchedType
    from coursedetails cd inner join coursetimes ct
    using (cRefNum)
    where cRefNum = 3816;
    

    其结果是:

    query 1 result

    我的第二个select语句是:

    select cRefNum, LISTAGG(fname|| ' ' || lname, ', ') within group (order by cRefNum) as Teachers
    from teachers
    where cRefNum = 3816
    group by cRefNum;
    

    其结果是:

    query 2 result

    我想要实现的是:

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  0
  •   Shivam Amin    8 年前
    select a.cRefNum, cName, CourseDesc, cTimeStart, cTimeEnd, cDay, Campus, Room, cSchedType, Teachers
    from
    (select cRefNum, cName,  cProgram || '-' || cCode || '-' || cSection as CourseDesc, cTimeStart, cTimeEnd, cDay, ct.cCampus as Campus, cBuildingSection || cRoom AS Room, cSchedType from coursedetails cd inner join coursetimes ct using (cRefNum) where cRefNum = 3816) a,
    (select cRefNum, LISTAGG(fname|| ' ' || lname, ', ') within group (order by cRefNum) as Teachers from teachers where cRefNum = 3816 group by cRefNum) b
    where a.cRefNum = b.cRefNum;
    

    这可以修复它,但确实很长,我不知道如何缩短它。