首页 > 数据库技术 > 详细

mysql ---排序、分组、并集操作、distinct

时间:2019-07-29 16:20:48      阅读:69      评论:0      收藏:0      [点我收藏+]

1、order  by 排序

select * from employee order by salary ASC limit 10; //查询出按salary排序最低的的10,名员工

2.distinct 获取不重复的唯一值

select distinct first_name from employee;

3.group by 分组统计

select first_name,count(*) cnt from employee group by first_name order by cnt DESC; // 按照first_name分组,并根据first_name出现次数按降序排列

4.union 和 union all

select * from a union select * from b;

select * from a union all select * from b;

上面两个语句都是执行并集操作,但union all 比union更快,union 实际上是union distinct,在进行表连接的时候会筛选掉重复记录,所以在表连接后会对产生的结果集进行排序运算,删除重复的记录再返回结果

mysql ---排序、分组、并集操作、distinct

原文:https://www.cnblogs.com/daijiabao/p/11264477.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!