读书人

问一个简单查询SQL排序的有关问题

发布时间: 2012-01-06 22:55:18 作者: rapoo

问一个简单查询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完全可以啊..NULL1
NULL1
NULL3
NULL3
1NULL
2NULL
21
24
32
55

[解决办法]
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

读书人网 >C#

热点推荐