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

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出现次数按降序排列

可以在group by 语句后添加 having 字句,对聚集结果进行筛选

select first_name,count(*) cnt from employee group by first_name having cnt > 10 order by cnt desc;

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,在进行表连接的时候会筛选掉重复记录,所以在表连接后会对产生的结果集进行排序运算,删除重复的记录再返回结果

转载于:https://www.cnblogs.com/daijiabao/p/11264477.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值