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

求一sql语句,急用,在等,
在一个表中有photo字段,可能为空,也可能不为空,要求一条sql语句,能够先显示字段不为空的记录,然后列出字段为空的记录,

id photo name number
1 jack 123  
2 shmit 789
3 pic\pic.gif join 456

要求结果显示

 pic\pic.gif join 456
  jack 123  
  shmit 789

------解决方案--------------------
SQL code
--原始数据:#T
create table #T(id int,photo varchar(11),name varchar(5),number int)
insert #T
select 1,'','jack',123 union all
select 2,'','shmit',789 union all
select 3,'pic\pic.gif','join',456

--查询成本:39.43%
select * from #T order by case photo when '' then 1 else 0 end

--查询成本:60.57%
select * from #T where photo<>''
union all
select * from #T where photo=''

--删除测试
drop table #T