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

相关文章:

  • 2021-08-06
  • 2021-12-16
  • 2021-09-25
  • 2021-08-29
  • 2022-12-23
  • 2022-01-01
  • 2022-01-01
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2021-12-31
  • 2021-07-06
  • 2022-12-23
  • 2021-07-16
  • 2021-04-04
相关资源
相似解决方案