我制作了两张这样的表
degree_plan student_record
------------------------------ ----------------------------
major course course_no ID course_no grade
------------------------------ ----------------------------
COE COE200 1 4455 1 A
COE COE305 2 4455 2 C
COE COE400 3 3333 4 B
SWE SWE214 4
SWE SWE344 5
SWE SWE444 6
course_no
是表格之间的关系
如何在SQL中编写查询以便像我这样where ID=4455 and the major = COE
--------------------------
major course grade
--------------------------
COE COE200 A
COE COE305 C
COE COE400 NULL
答案 0 :(得分:0)
select *
from degree_plan
left join studen`t_record
on studen`t_record.course_no = degree_plan.course_no
where major = 'COE'
你需要在哪里过滤
答案 1 :(得分:0)
试试这个:
select a.major, a.course, b.grade
from degree_plan a
left join studen`t_record b on b.course_no = a.course_no
where a.major = 'COE'
你甚至不需要喜欢条款,因为主要领域不长于COE
答案 2 :(得分:0)
试试这种方式
select a.mjor, a.course, b.grade
from degree_plan as a
left join student_record as b on a.course_no=b.course_no and b.id=4455
where a.major='COE'
答案 3 :(得分:0)
SELECT degree_plan.major, degree_plan.course, studen't_record.grade
FROM degree_plan
LEFT JOIN Student_record ON degree_plan.course_no=student_record.course_no where degree.major='COE';