先做这一题,然后举一反三。
1.select name from table;
条件是:分数都大于60 那就先查分数都>60的
2.select name,min(score) mincj from table group by name; (对应每个人 最低分的一科出来了
group by)
3.多行多列的子查询
select name from ( select name,min(score) mincj from table group by name ) where mincj>60;
二、求一个成绩表table中分数超过60的人的科目subject 这个题目怪怪的,我修改一下
求一个成绩表中每门分数都超过60的人的科目
1.select subject from table
2.select name,min(score) mincj from table group by name; (超过60分的人) 也是多行多列的子查询
3. select subject from table
where name in (select name from ( ( select name,min(score) mincj from table group by name having mincj > 60 )));
这是一个group by和函数一起用的用法 子查询的嵌套用法
下面这样写,是为了防止有两个平均薪水最高的部门
题目改正:部门的平均薪水等于部门平均最高薪水