这样的查询怎么搞定??????

yezie 2004-06-09 01:04:51
f1 f2
a 0
b 1
c 2
d 0

f1,f2是字段名,
我想查询后的表的第一行为: b 1
然后接下去的order by f2 desc
用union好像写不出
...全文
97 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2004-06-09
  • 打赏
  • 举报
回复
select * from 表
order by iif(f1='b' and f2=1,0,1),f2 desc
zjcxc 元老 2004-06-09
  • 打赏
  • 举报
回复
晕,怎么老是ACCESS数据库到sql版问,又不写明白
yezie 2004-06-09
  • 打赏
  • 举报
回复
晕,是access数据库
zjcxc 元老 2004-06-09
  • 打赏
  • 举报
回复
--测试

--测试数据
declare @t table(f1 varchar(10),f2 int)
insert @t select 'a',0
union all select 'b',1
union all select 'c',2
union all select 'd',0

select * from @t
order by case when f1='b' and f2=1 then 0 else 1 end,f2 desc


/*--测试结果

f1 f2
---------- -----------
b 1
c 2
d 0
a 0

(所影响的行数为 4 行)
--*/
victorycyz 2004-06-09
  • 打赏
  • 举报
回复

select ... order by (case when f2=1 then 0 else 1 end), f2 desc
zjcxc 元老 2004-06-09
  • 打赏
  • 举报
回复
select * from 表
order by case when f1='b' and f2=1 then 0 else 1 end,f2 desc

34,875

社区成员

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

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