【发布时间】:2020-06-23 07:12:23
【问题描述】:
我有两张桌子。
- 学生
- 学生兴趣
表:学生
Id | Student Name
------------------
1 | John
2 | Alice
表:学生兴趣
Id | SId | Interest
------------------
1 | 1 | Mathematics
2 | 1 | Science
1 | 2 | Environment
2 | 2 | English
2 | 2 | Mathematics
这两个表与“student Interest”表中的外键相连
现在我想要对“数学”和“科学”都感兴趣的学生的名字
我试过了
Select s.Name from Student s
Inner Join StudentInterest si
ON
s.Id = si.SId
Where si.Interest IN ('Mathematics' , 'Science')
但它显示了两个学生,因为这两个学生都对“数学”感兴趣 结果应该只有 1 个名为“John”的学生
【问题讨论】: