Precautions for order by + multiple columns in SQL

order byWhen using + multiple columns in SQL statements , you need to pay attention to:

  1. When sorting, it is first sorted according order byto the first one , and then sorted according to the second one, and so on.colcol
  2. When sorting, if you don't specify ASCwhether or DESChow, the default is ASC.
  3. ASCand DESConly affect the first one in front of them col, colnot the others. as follows:
    order by col1 Desc,col2 此时先col1降序排序,然后col2升序排列。
    order by col1 ,col2 Desc 此时先col1升序排序,然后col2降序排列。

Guess you like

Origin blog.csdn.net/qq_42540393/article/details/118555047