Multiple ascending order is not working in Mysql

后端 未结 2 1864
旧时难觅i
旧时难觅i 2021-01-26 01:37

I have one table called as request and there are three columns called as Id, want, teach. I have to display want and teach co

2条回答
  •  时光取名叫无心
    2021-01-26 02:12

    You are not getting the point of multi order here.

    firstly , by default, most of dbms sorting as ASC.

    Multiple ordering depending on the order of sorted columns, which is mean that -so to speak- :-

    " hey sql ! select some result from my table , order them by col1 and group them by this order , then this sorted or grouped data set , sort them by col2. "

    it's kind of multidimensional sorting so to speak.

    take this as an example :

    +------+---------+-------+                   +------+---------+-------+
    |  id  |   want  | teach |                   |  id  |   want  | teach |
    +------+---------+-------+                   +------+---------+-------+
    |   1  |    1    |   2   |    ORDER BY       |   2  |    1    |   1   |
    |   2  |    1    |   1   |       want asc,   |   1  |    1    |   2   |
    |   3  |    2    |   1   |       teach asc   |   4  |    1    |   2   |
    |   4  |    1    |   2   |                   |   3  |    2    |   1   |
    +------+---------+-------+                   +------+---------+-------+
    

    and when you revert the order of sorted columns like this :

    +------+---------+-------+                   +------+---------+-------+
    |  id  |   want  | teach |                   |  id  |   want  | teach |
    +------+---------+-------+                   +------+---------+-------+
    |   1  |    1    |   2   |    ORDER BY       |   2  |    1    |   1   |
    |   2  |    1    |   1   |       teach asc,  |   3  |    2    |   1   |
    |   3  |    2    |   1   |       want asc    |   1  |    1    |   2   |
    |   4  |    1    |   2   |                   |   4  |    1    |   2   |
    +------+---------+-------+                   +------+---------+-------+
    

提交回复
热议问题