SQL 服务器中的自定义顺序,如 P、A、L、H [英] Custom order by in SQL server like P, A, L, H

查看:13
本文介绍了SQL 服务器中的自定义顺序,如 P、A、L、H的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是 ASCDESC.... 按自定义订购...

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

我曾尝试使用 case 但没有成功

I have tried using case but not successfully

SELECT * FROM Customers
ORDER BY case country
when 'P' then 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

这篇关于SQL 服务器中的自定义顺序,如 P、A、L、H的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆