如下学生成绩表,查询各科成绩都不低于80分的学生。表名 tb
| stu | course | score |
|---|---|---|
| 张三 | 数学 | 90 |
| 张三 | 语文 | 80 |
| 张三 | 英语 | 70 |
| 李四 | 数学 | 90 |
| 李四 | 语文 | 87 |
| 李四 | 英语 | 90 |
| 王五 | 数学 | 88 |
| 王五 | 语文 | 78 |
| 王五 | 英语 | 89 |
解答思路: 1、常规,查询记录中stu不在低于80的stu中的;
select stu from tb where stu not in (select distinct stu from tb where score<80);
2、统计函数;
select stu from tb group by stu having min(score)>80;