【发布时间】:2015-12-09 00:00:56
【问题描述】:
您好,我有一个名为 student_subject_table 的 mysql 表:
+----+-------------+---------------------+
| id | student_id | subject |
+----+-------------+---------------------+
| 1 | 7 | math |
| 2 | 7 | physics |
| 3 | 7 | chemistry |
| 8 | 8 | math |
| 9 | 8 | physics |
| 10 | 8 | chemistry |
| 11 | 8 | biology |
+----+-------------+---------------------+
我正在尝试获取仅以数学、物理和化学为科目的学生的 ID。
我试过 in 子句:
select student_id
from student_subject table
where
subject in ('math', 'physics', 'chemistry')
GROUP BY (student_id)
正如预期的那样,我得到了 7 和 8 作为 student_id。 在上表中,我只需要 student_id = 7。
mysql有什么办法可以做到吗?
请帮忙。
【问题讨论】:
标签: mysql