表结构
a b
1 5
0 2
1 4
1 7
0 11
如上表,我想查询的结果是,先把a=1的列安b的降序排列,后面在把a<>1的列安b降序排列,
这个语句改怎么写呀
a b
1 5
0 2
1 4
1 7
0 11
如上表,我想查询的结果是,先把a=1的列安b的降序排列,后面在把a<>1的列安b降序排列,
这个语句改怎么写呀
解决方案 »
- 100分,table1 采用 Update触发器,如何用最简单的方式识别改了哪个字段,并记日志
- 服务器进程的一个重要组成部分已被页面调出
- 求E-R图帮助
- 数据转换问题:sql server---->foxpro 2.0
- SQL SERVER2005安装后的是否为强密码设置在那里修改
- 菜鸟一问(送分)
- 执行存储过程的小问题,急!急!!!
- 请邹建大哥 帮忙解决一个向表添加多条记录的存储过程?
- 我在SQL Server2000写了一些触发器,结果发现它导致系统运行很慢.请问有什么办法来优化触发器的运行速度没?谢谢!
- 请教各位!我的oracle8.1.6装在win2k出问题?了
- 删除SQL server 2000 日志文件,有谁实际操作过,这对数据库有影响吗?或是风险?
- 储存过程的参数问题?
from t
order by case when a = 1 then 9999999 - b else b end desc
insert @t select
1, 5 union select
0, 2 union select
1 , 4 union select
1 , 7 union select
0 , 11
select *
from @t
order by case when a = 1 then 0 else 1 end ,b desc/*
a b
----------- -----------
1 7
1 5
1 4
0 11
0 2(所影响的行数为 5 行)*/
declare @t table (a int,b int)
insert into @t values(1,5)
insert into @t values(0,2)
insert into @t values(1,4)
insert into @t values(1,7)
insert into @t values(0,11)select * from
(
select top 100 PERCENT * from @t where a=1 order by b desc
) a
union all
select * from
(
select top 100 PERCENT * from @t where a<>1 order by b
) b
a b
----------- -----------
1 5
1 4
1 7
0 2
0 11(5 行受影响)
insert @t select
1, 5 union select
0, 2 union select
1 , 4 union select
1 , 7 union select
0 , 11 -- a=1 asc ,a<> 1 desc
select *
from @t
order by case when a = 1 then -b else b end desc/*
a b
----------- -----------
0 11
0 2
1 4
1 5
1 7(所影响的行数为 5 行)
*/
a b
1 5
0 2
1 4
1 7
0 11 select * from 表
where a=1
order by b descunion
select * from 表
where a <> 1
order by b desc
declare @tb table(a int,b int)
insert into @tb
select 1,5
union
select 0,2
union
select 1,4
union
select 1,7
union
select 0,11select * from @tb
order by case when a=1 then 0 else 1 end,b desc