SQL 查询问题 在线等
A B
1 2006/11/30
02006/12/31
12006/9/30
12006/11/30
02006/6/30
02006/3/30
12006/4/30
把A列值=1 并且 B列按时间排序 最新的排在最前面
谢谢
[解决办法]
create table T(A int, B datetime)
insert T select 1, '2006-11-30 '
union all select 0, '2006-12-31 '
union all select 1, '2006-9-30 '
union all select 1, '2006-11-30 '
union all select 0, '2006-6-30 '
union all select 0, '2006-3-30 '
union all select 1, '2006-4-30 '
select * from T
order by (case when A=1 then -1 else A end), B desc
A B
----------- ------------------------------------------------------
1 2006-11-30 00:00:00.000
1 2006-11-30 00:00:00.000
1 2006-09-30 00:00:00.000
1 2006-04-30 00:00:00.000
0 2006-12-31 00:00:00.000
0 2006-06-30 00:00:00.000
0 2006-03-30 00:00:00.000
(7 row(s) affected)