【发布时间】:2016-10-19 12:50:16
【问题描述】:
我有如下所述的主表和详细表(带有代表性数据)。我想为生物学和化学均获得“A”的学生选择(符合 mysql 的)Student.id。
Students grades
id name id student_id class grade
1 ken 1 1 Biology A
2 beth 2 1 Chemistry A
3 joe 3 1 Math B
4 2 Biology A
5 2 Chemistry A
6 2 Math A
7 3 Biology B
8 3 Chemistry A
9 3 Math A
目前,我只是将所有数据提取到我的程序 (java) 中,但我认为 SQL 中必须有一种方法来获取正确的记录。
我从上面的数据中寻找的结果是 1 和 2(ken 和 beth)。我已经尝试了一些使用连接和内部选择的变体,但不能完全让它工作。我的主要问题似乎是我正在对我的详细记录进行与运算,例如,...where grades.class='Biology' and grades.grade='A'
我查看了SQL select from header table where detail table rows have multiple values,但这并没有完全让我到达我需要的地方。
非常感谢您的帮助。
【问题讨论】: