• mysql order by null


    mysql> explain select * from user group by name,age \G
    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: user
    type: ALL
    possible_keys: NULL
    key: NULL
    key_len: NULL
    ref: NULL
    rows: 36
    Extra: Using temporary; Using filesort
    1 row in set (0.00 sec)

    mysql> explain select * from user group by name,age order by null \G
    *************************** 1. row ***************************
    id: 1
    select_type: SIMPLE
    table: user
    type: ALL
    possible_keys: NULL
    key: NULL
    key_len: NULL
    ref: NULL
    rows: 36
    Extra: Using temporary
    1 row in set (0.00 sec)

    注意有下划线的红色字体,是没有加‘order by null’出现的提示,表示进行了排序,以下是结果:

    mysql> select * from user group by name,age order by null
    +-------------+------+----+
    | name | age | id |
    +-------------+------+----+
    | zhangzhibin | 13 | 1 |
    | lisi | 13 | 2 |
    | wangwu | 18 | 3 |
    | zhangzhibin | 19 | 4 |
    | lisi | 12 | 5 |
    | wangwu | 13 | 6 |
    | zhangzhibin | 11 | 7 |
    | lisi | 14 | 8 |
    | wangwu | 16 | 9 |
    | zhangzhibin | 18 | 10 |
    | wangwu | 11 | 12 |
    | lisi | 15 | 14 |
    | wangwu | 10 | 15 |
    | lisi | 18 | 17 |
    | wangwu | 17 | 18 |
    | zhangzhibin | 12 | 19 |
    | lisi | 10 | 20 |
    | lisi | 19 | 23 |
    | wangwu | 14 | 24 |
    | lisi | 11 | 26 |
    | zhangzhibin | 17 | 28 |
    | wangwu | 15 | 30 |
    | zhangzhibin | 14 | 34 |
    +-------------+------+----+
    23 rows in set (0.00 sec)

    mysql> select * from user group by name,age;
    +-------------+------+----+
    | name | age | id |
    +-------------+------+----+
    | lisi | 10 | 20 |
    | lisi | 11 | 26 |
    | lisi | 12 | 5 |
    | lisi | 13 | 2 |
    | lisi | 14 | 8 |
    | lisi | 15 | 14 |
    | lisi | 18 | 17 |
    | lisi | 19 | 23 |
    | wangwu | 10 | 15 |
    | wangwu | 11 | 12 |
    | wangwu | 13 | 6 |
    | wangwu | 14 | 24 |
    | wangwu | 15 | 30 |
    | wangwu | 16 | 9 |
    | wangwu | 17 | 18 |
    | wangwu | 18 | 3 |
    | zhangzhibin | 11 | 7 |
    | zhangzhibin | 12 | 19 |
    | zhangzhibin | 13 | 1 |
    | zhangzhibin | 14 | 34 |
    | zhangzhibin | 17 | 28 |
    | zhangzhibin | 18 | 10 |
    | zhangzhibin | 19 | 4 |
    +-------------+------+----+
    23 rows in set (0.00 sec)

    为了显示出order by null 这句的作用我选择了 name 和 age 两个字段进行分组,若只选name来进行分组,那么最后的结果只有三条,不容易看出结果

  • 相关阅读:
    编译
    Package vim is not available, but is referred to by another package.
    Http 请求处理流程 Asp.Net 编程 TraceFact.Net
    JavaScript中两个感叹号的作用
    IE6 链接失效 <a>失效 不能点击
    父元素绝对定位 子元素在IE6 不能点击
    ie6 ie7 绝对定位 相对定位 层被遮住
    HTTP深入浅出http请求
    主流的js template引擎 前端模板
    第3章:基本概念(一)
  • 原文地址:https://www.cnblogs.com/iLoveMyD/p/2397578.html
Copyright © 2020-2023  润新知