Custom order by in SQL server like P, A, L, H [closed]

无人久伴 提交于 2019-11-28 22:19:53

问题


Not ASC or DESC.... Order by custom...

I have tried using case but not successfully

SELECT * FROM Customers
ORDER BY case country
when 'P' then 1 …

This is what I want:


回答1:


SELECT * FROM Customers
ORDER BY case when country = 'P' then 1
              when country = 'A' then 2
              when country = 'L' then 3
              when country = 'H' then 4
              else 5
         end asc


来源:https://stackoverflow.com/questions/19196475/custom-order-by-in-sql-server-like-p-a-l-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!