嗨,我只是sql的新手,我不明白工会的工作方式。它说我需要找回所有其他与“ s001”学习过相同课程的学生(非s001),这些学生使用联合,相交或减法学习了相同的课程。我进行查询,但没有成功,它有错误。我的查询是:select student.* from student,subjcode where subjcode.sno!='s001' union select subjcode.* from subjcode,student where subjcode.sno='s001' and subjcode.sno=student.sno;
表子代码为:
sno cno score
S001 C001 78.90
S001 C002 82.90
S001 C003 59.00
S002 C001 80.90
S002 C002 72.90
S003 C001 81.90
S003 C002 81.90
S004 C001 60.90
S005 C002 50.00
S006 C002 50.00
餐桌学生是:
sno sname sage ssex
S003 BILL 25 M
S004 STEVE 20 F
S005 BAKR 20 F
S006 TOM 21 M
S007 JERRY 21 M
S008 MACY 21 F
S009 MICK 23 F
S010 COOKER 22 F
请有人可以帮我这个忙。非常感谢!
最佳答案
听起来您在寻找INNER JOIN
而不是UNION
。
这是否会给您带来您想要的结果?
SELECT student.*, subjcode.cno, subjcode.score
FROM student
INNER JOIN subjcode ON subjcode.sno = student.sno
WHERE student.sno LIKE '%S001%';