Sort MySQL results alphabetically, but with numbers last

前端 未结 3 1786
天命终不由人
天命终不由人 2020-12-10 16:55

Often, sorting is done with symbols sorted to the top, like 0 or * or &. This is the default way that mysql sorts; numbers and sy

3条回答
  •  死守一世寂寞
    2020-12-10 17:24

    Select ...
    From ...
    Order By Case When Col Like '[0-9]%' Then 1 Else 0 End Asc
        , Col
    

    Another solution that would account for special characters:

    Select ...
    From ...
    Order By Case When Col Like '[A-Z]%' Then 0 Else 1 End Asc
        , Col
    

提交回复
热议问题