日期:2014-05-18  浏览次数:20811 次

问一个简单查询SQL排序的问题
我有一个表   case
字段   a     ,     b
想查询的排序为

先查a为空   按b排序
再a不为空   按b排序

请朋友帮下

------解决方案--------------------
select a,b from case where a is null order by b;

select a,b from case where a is not null order by b;
------解决方案--------------------
select a,b from case where a is null order by b
union all
select a,b from case where a is not null order by b;

不知道是不是你所要的
------解决方案--------------------
是啊select a,b from case order by a,b完全可以啊..NULL 1
NULL 1
NULL 3
NULL 3
1 NULL
2 NULL
2 1
2 4
3 2
5 5

------解决方案--------------------
create table #(nId int identity(1,1) primary key, a nvarchar(1000), b nvarchar(1000))

insert # select a, b from case where a is null order by b;
insert # select a, b from case where a is not null order by b;
select a,b from # order by nId