sql查询按指定的顺序排序

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:26:10
求高手指教一个查询
select * from 表 order by sunxun
这个查询 查出的结果 只能按sunxun这个字段 要么升序排要么降序排 而现在要求按照指定的顺序排 比如 sunxun 这个字段的值可能是 A或B或C或D 升序 降序只能排出ABCD 或DCBA 而我现在想要的是BCAD 请问这个排序怎么写? 最好不要用子查询.
就是这么要求的 就好象凭什么是ABCD一样 现在就要BCAD

可以,按你说的得这么写

select *
from 表
order by (select case sunxun when 'A' then 3 when 'B' then 1 when 'C' then 2 when 'D' then 4 end)

试试吧,SQL SERVER适用。

说的不明白呀,bcda难道是随即排序?

什么叫排序?查查字典再说吧