当前位置: 代码迷 >> Sql Server >> 一个特殊的排序有关问题
  详细解决方案

一个特殊的排序有关问题

热度:55   发布时间:2016-04-27 15:44:33.0
一个特殊的排序问题
字段数据如下
0
0
0
1
0
3
0
2
7
5
0
4
6


如何能做到如下排序
1
2
3
4
5
6
7
0
0
0
0
0
0

------解决方案--------------------
declare @t table(id int)
insert into @t(id)
select 0
union all select 0
union all select 0
union all select 1
union all select 0
union all select 3
union all select 0
union all select 2
union all select 7
union all select 5
union all select 0
union all select 4
union all select 6

select id from @t order by case when id=0 then 99999 else id end
------解决方案--------------------
ACCESS這麼寫

Select * From dbname Order By IIF(cost= 0, 9999999, cost)
  相关解决方案