在本次作业中,我必须使用单个查询显示学生ID或标有“ Id”的课程ID,以及学生名称或标有“ Student or课程”与教授“布朗”有关。 我不知道如何在select中实现此条件,以使查询根据条件显示两个之一。
学生具有外部prof_id,而教授具有外部course_id。
我只能想出一个四列,两次显示Id,两次显示“学生或课程”。
我尝试使用Case或“ with”-“ as”子句,但似乎不起作用
我当前的查询是:
SELECT s_id AS "Id", s_name AS "Student or course",
r.course_no AS "Id", course_name AS "Student or course"
FROM students JOIN professors f ON ( f.prof_id LIKE prof_id)
JOIN course c ON (c.prof_id = f.prof_id)
WHERE f.f_name LIKE 'Brown';
答案 0 :(得分:0)
select to_char(s_id) "Cod", s_last "Student sau curs",
'Student' "Tip"
from student join faculty using(f_id)
where lower (f_last) = 'brown'
union
select to_char(c_sec_id), course_name, 'Curs'
from faculty join course_section using (f_id)
join course using (course_no)
where lower (f_last) = 'brown';