如何让ORDER BY 按指定的顺序排序?

GreenTLG 2006-08-02 04:33:32
表里有个列叫Type,是商品类别,就3种情况:S,A,B。现在我需要按照SAB的顺序排序,那位大侠能帮帮忙啊,

SELECT *
FROM tbl_test
ORDER BY "@#$$%#$%@$@#$@$@#@$这里应该咋写?"

两个表联合查肯定没问题,现在就是想如果单独用这个表的话。咋弄。多谢啦!!!!
...全文
1025 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
十一月猪 2006-08-03
  • 打赏
  • 举报
回复
全了
;)
being21 2006-08-02
  • 打赏
  • 举报
回复
MARK!!!
xyxfly 2006-08-02
  • 打赏
  • 举报
回复
呵呵,我在另一個地方看的3種方法都全了
charindex
case

union all
chuifengde 2006-08-02
  • 打赏
  • 举报
回复
order by charindex(type+',','S,A,B,')
昵称被占用了 2006-08-02
  • 打赏
  • 举报
回复
这个效率差,虽然看起来简单
freeliu 2006-08-02
  • 打赏
  • 举报
回复
select *(这里应该列出标的字段了,否则会包含自查询中的seq)
from (select *, case type when 'S' then 1 when 'A' then 2 else 3 end as seq from tbl_test) X
order by seq
昵称被占用了 2006-08-02
  • 打赏
  • 举报
回复
order by charindex(type,'SAB')

eszuorenhui 2006-08-02
  • 打赏
  • 举报
回复
select *
from tbl_test
order by s+a+b
昵称被占用了 2006-08-02
  • 打赏
  • 举报
回复
order by case type when 's' then 1
when 'a' then 2 when 'b' then 3 else 4 end
九斤半 2006-08-02
  • 打赏
  • 举报
回复
表里有个列叫Type,是商品类别,就3种情况:S,A,B。现在我需要按照SAB的顺序排序,那位大侠能帮帮忙啊,

SELECT *
FROM tbl_test
ORDER BY "@#$$%#$%@$@#$@$@#@$这里应该咋写?"
----------------------------------------------
换个方法
select * from table where type='S' union all
select * from table where type='A' union all
select * from table where type='B'

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧