需要帮助结合两个选择语句的结果

时间:2017-12-13 05:26:01

标签: oracle-sqldeveloper

我的第一个选择陈述是:

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 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 个答案:

答案 0 :(得分:0)

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;

这解决了这个问题,但确实很长,而且我不知道缩短它。