试图让这个查询起作用
SELECT studentid, fName, lName, dob
FROM Student
WHERE courseNo IN
(SELECT courseNo
FROM Student
WHERE courseNo = 1001 IN
(SELECT dob
FROM Student
WHERE dob < `1985-09-12`));
但出于某种原因,它说的是空集?
所有数据都在Student的同一个表中。如果有帮助,dob的格式为YYYY-MM-DD。
答案 0 :(得分:3)
我想你想做这样的事情:
SELECT studentid,fName,lName,dob From Student
where courseNo ='1001' and dob<'1985-09-12'
答案 1 :(得分:3)
WHERE courseNo = 1001和IN之间缺少一个属性。 我不确定你到底需要什么,但也许可能是这样的?:
SELECT studentid, fName, lName, dob
FROM Student
WHERE courseNo IN
(SELECT courseNo
FROM Student
WHERE courseNo = 1001 AND dob IN
(SELECT dob
FROM Student
WHERE dob < '1985-09-12'));
如果是这样,请使查询更简单,它适合您?尝试这样的事情:
SELECT studentid, fName, lName, dob
FROM Student
WHERE courseNo = 1001 and dob < '1985-09-12';