1
ID_Number|Subject_Code|Grade
000001   |Math        |Dropped
000001   |English     |Passed
000001   |Physics     |Passed
000002   |Math        |Passed
000002   |English     |Passed
000002   |Physics     |Passed
000003   |Math        |Passed
000003   |English     |Passed
000003   |Physics     |Passed

现在我想要SELECT DISTINCT ID_Number其中所有的subject_code都应该有等级作为通过,查询应该返回000002和000003,因为000001有1个放弃的主题,其他不包括的等级是'撤回'和'失败'。

4

1 回答 1

3
SELECT DISTINCT ID_Number
FROM   <table>
WHERE  ID_Number not in(select ID_Number from <table> where Grade <> 'Passed')

SQL小提琴演示

于 2012-11-22T06:32:40.543 回答