首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一条order by的检索语句解决方法

2012-05-12 
求一条order by的检索语句有表如下id name41 d7 g2 b3 c65现在要一条检索语句最后得出的结果是1 d2 b3 c7

求一条order by的检索语句
有表如下
id name

1 d
7 g
2 b
3 c
6  


现在要一条检索语句最后得出的结果是
1 d
2 b 
3 c
7 g
4
5
6
如果name有值,就按照id顺序排列,如果name没有值,就排在后面(同样也是name没有值里面也按照id顺序排列)

[解决办法]

SQL code
select id,namefrom TBgroup by id,name,case when name IS null then 1 else 0 end order by case when name IS null then 1 else 0 end /*1    d2    b3    c7    g4    NULL5    NULL6    NULL
[解决办法]
SQL code
select id,namefrom TBorder by case when name IS null then 1 else 0 end ,id 

热点排行
Bad Request.