A        B
1  2006/11/30    
0 2006/12/31
1 2006/9/30
1 2006/11/30
0 2006/6/30
0 2006/3/30
1 2006/4/30把A列值=1 并且 B列按时间排序 最新的排在最前面
谢谢

解决方案 »

  1.   

    select *
    from table
    where A = 1
    order by b DESC
      

  2.   

    select * 
    from table 
    order by a desc , b desc
      

  3.   

    select * from table where a=1 order by datetime(b) desc
      

  4.   

    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 A desc, B desc--result
    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)
      

  5.   

    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 descA           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)