一个排序的简单问题?多条件排序

gaopei1122 2007-04-28 10:13:26
表1

a b

1 340
0 320
0 210
1 329
1 403
0 322

想先把a=1的按升序排列,然后a<>1的再按升序排列,该怎么写查询语句
...全文
218 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ALLEN625314 2007-04-28
  • 打赏
  • 举报
回复
create table #a(
a int,
b int)
go
insert into #a
select 1, 340
union all
select 0, 320
union all
select 0, 210
union all
select 1, 329
union all
select 1, 403
union all
select 0 , 322
go
select * from #a order by a desc,b asc

--drop table #a
---涛声依旧--- 2007-04-28
  • 打赏
  • 举报
回复
三、四樓都可以
jyxhz 2007-04-28
  • 打赏
  • 举报
回复
select * from 表1 where a=1 order by b
union all
select * from 表1 where a<>1 order by b
kenny_appleso 2007-04-28
  • 打赏
  • 举报
回复
select a,b from 表1 order by case a when 1 then 0 else 1 end,b asc
青锋-SS 2007-04-28
  • 打赏
  • 举报
回复
select a,b from 表1 order by case a when 1 then 0 else 1 end,b asc
青锋-SS 2007-04-28
  • 打赏
  • 举报
回复
select a,b from 表1 order by a desc,b asc

34,590

社区成员

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

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