1. 找出收入最高的员工:
select * from recon_feed_vt_details where left_break=( select max(left_break) from recon_feed_vt_details);

3. 找出第二名的学生
先找出第一名max grade, then where grade< max grade----逐层嵌套,那我找100名岂不套繁琐了?
select max(grade) from student where grade<(select max(grade) from student);

4. Mysql分页查询:


2. Where和having区别:
having是分组的时候筛选,一定和group by 连用:
优先级: where>聚合函数sum avg max min count 优先级 > having
找出部门中工资大于2000的人数不止一人的所有部门
select DepID,count(*) from table
where salary >2000
group by DepID
having count(*) >=2

5. Union Union all

union会去掉重复的行。
使用union all不会去重复。

 

posted on 2017-11-05 20:13  立中宵  阅读(144)  评论(0编辑  收藏  举报