假设一个表有A,B两字段 A字段的内容表示年份 B字段的内容表示月份
查询出A和B 查询的结果怎么按年月排序?
请大家教教我!

解决方案 »

  1.   

    select * from 表
    order by a,b
      

  2.   

    if object_id('tb') is not null
       drop table tb
    go
    create table tb(A int, B int)
    insert into tb
    select 2007,1 union all
    select 2007,10 union all 
    select 2007,2 union all 
    select 2007,4 union all 
    select 2007,3 union all 
    select 2007,5 union all 
    select 2008,2 union all 
    select 2007,1 
    select A,B from tb
    order by A,B
     
      

  3.   

    字符型月份的话
    select * from 表
    order by a+right('0'+b,2)
      

  4.   

    ------------加个DESC
    if   object_id('tb')   is   not   null
          drop   table   tb
    go
    create   table   tb(A   int,   B   int)
    insert   into   tb
    select   2007,1   union   all
    select   2007,10   union   all  
    select   2007,2   union   all  
    select   2007,4   union   all  
    select   2007,3   union   all  
    select   2007,5   union   all  
    select   2008,2   union   all  
    select   2007,1  
    select   A,B   from   tb
    order   by   A,B DESC
      

  5.   

    order   by   A desc,B desc