一个特殊的排序问题

ppxstar 2007-03-31 10:22:05
字段数据如下
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
...全文
151 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
paoluo 2007-03-31
  • 打赏
  • 举报
回复
ACCESS這麼寫

Select * From dbname Order By IIF(cost= 0, 9999999, cost)
ppxstar 2007-03-31
  • 打赏
  • 举报
回复
我查了一下,access不能用这个语句,只能用iif

但我的语句总是不成功

select *,iif(cost=0,999,cost) from dbname order by cost

这样写不对吗??
paoluo 2007-03-31
  • 打赏
  • 举报
回复
ACCESS中這麼寫

Select * From A Order By IIF(ID = 0, 9999999, ID)
gahade 2007-03-31
  • 打赏
  • 举报
回复
select id from @t order by case when id=0 then (select max(id)+1 from @t) else id end
ppxstar 2007-03-31
  • 打赏
  • 举报
回复
access 是否支持你们的写法呢??
ppxstar 2007-03-31
  • 打赏
  • 举报
回复
我sql语句不是很精,看不太懂
上面的数据例子只是显示了一个字段,我的数据库里还有很多其它字段
并且这个字段里的数据还在不段增加。
hrb2008 2007-03-31
  • 打赏
  • 举报
回复
select col from tb
order by
case col
when 0 then 90
else col
end
gahade 2007-03-31
  • 打赏
  • 举报
回复
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

22,302

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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