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

  • 相关阅读:
    人的一生为什么要努力 &1
    数据库_数据库系统概论
    电子商务安全
    虚拟专用网技术
    人的一生为什么要努力
    数据备份与恢复技术
    入侵检测技术
    简历模板连接
    防火墙技术
    字节与位
  • 原文地址:https://www.cnblogs.com/daijiabao/p/11264477.html
Copyright © 2011-2022 走看看