首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-01-06 
问一个简单查询SQL排序的问题我有一个表case字段a,b想查询的排序为先查a为空按b排序再a不为空按b排序请朋

问一个简单查询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

热点排行