怎么按照指定次序对结果集进行排序.

wd_6532 2008-07-09 11:53:56
比如 有记录

1
0
3
7
5

我想把1排在3排在最前面,然后其他的倒序排列

怎么实现.
...全文
92 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
utpcb 2008-07-09
  • 打赏
  • 举报
回复
选择判断的意思
octwind 2008-07-09
  • 打赏
  • 举报
回复
select * from tb where id=1 union all
select * from tb where id=3 union all
select * from tb t where not exists (select 1 from tb where id=t.id and (id=1 or id=3)) order by id desc
wd_6532 2008-07-09
  • 打赏
  • 举报
回复
楼上语句是什么意思
wgzaaa 2008-07-09
  • 打赏
  • 举报
回复
select *,(1-a)*(1+a) from #1 order by (case when a=1 then 99999 else a end) desc
wd_6532 2008-07-09
  • 打赏
  • 举报
回复
哈哈,打错了.

把1排在最前面,其他的到排序.

1楼答案应该是正确的,谢谢.
wgzaaa 2008-07-09
  • 打赏
  • 举报
回复
把1排在3排在最前面---什么意思  
chuifengde 2008-07-09
  • 打赏
  • 举报
回复
select * from [Table] order case [Field] when 1 then 0 when 3 then 1 else 2 end,[Field] desc

34,590

社区成员

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

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