日期:2014-05-17 浏览次数:20654 次
select * from [Table]
order by case when close_time is null then 0 else 1 end,,close_time desc,start_time desc
declare @table table(start_time datetime,close_time datetime)
insert into @table(start_time,close_time)
values ('2012-3-2' ,null),
('2012-3-15' ,'2012-3-4'),
('2012-3-4' ,'2012-3-3'),
('2012-3-18' ,null)
select *
from @table
order by case when close_time IS null
then 1
else 0
end desc ,
case when close_time IS null
then start_time
else close_time
end desc
/*
start_time close_time
2012-03-18 00:00:00.000 NULL
2012-03-02 00:00:00.000 NULL
2012-03-15 00:00:00.000 2012-03-04 00:00:00.000
2012-03-04 00:00:00.000 2012-03-03 00:00:00.000
*/