读书人

一个特殊的排序有关问题

发布时间: 2012-02-07 17:45:37 作者: rapoo

一个特殊的排序问题
字段数据如下
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)

读书人网 >SQL Server

热点推荐