SELECT stu.First_Name, stu.Last_Name, stu.Phone
FROM Student stu
JOIN Enrollment e
ON stu.Student_Id = e.Student_Id
JOIN Section sec
ON e.Section_Id = sec.Section_Id
JOIN Course c
ON sec.Course_No = c.Course_No
WHERE c.Description = 'Systems Analysis' AND c.Description = 'Project Managment'
嘿所有,希望是今天的最后一个问题(我很抱歉)。我想知道是否有办法检查多个字符串条件(是AND,而不是OR)。当我只使用一个我的联接工作正常,但我似乎无法使用两者。我的教科书希望我只使用课程的字符串关键字来解决它。
答案 0 :(得分:2)
使用OR
并仅过滤具有相同实例数的行到WHERE
子句中指定的过滤器数。
SELECT stu.First_Name,
stu.Last_Name,
stu.Phone
FROM Student stu
JOIN Enrollment e
ON stu.Student_Id = e.Student_Id
JOIN Section sec
ON e.Section_Id = sec.Section_Id
JOIN Course c
ON sec.Course_No = c.Course_No
WHERE c.Description IN ('Systems Analysis', 'Project Managment') -- two values
GROUP BY stu.First_Name, stu.Last_Name, stu.Phone
HAVING COUNT(*) = 2 -- rows must have 2 instances