select max(月份) from 表名 where 年份 in(select max(年份) from 表名 where 月份 in('01','02','03','04','04','06','07','08','09','10','11','12'))

解决方案 »

  1.   

    --建立測試環境
    Create Table TEST
    (ID Int,
     月份 Varchar(10),
     年份 Int)
    Insert TEST Select 1,   '12',   2005
    Union All Select 2,   '01',   2006
    Union All Select 3,   '02',   2006
    Union All Select 4,   '03',   2006
    Union All Select 5,   '04',   2006
    Union All Select 6,   '06',   2006
    GO
    --測試
    Select TOP 1 * From TEST A Where (Select Count(*) From TEST Where 月份<=A.月份 And 年份=A.年份)=月份 Order By 年份 Desc,月份 Desc
    GO
    --刪除測試環境
    Drop Table TEST
    --結果
    /*
    ID 月份 年份
    5 04 2006
    */
      

  2.   

    itblog(^ω^) 得出來的結果是錯誤的。
      

  3.   

    paoluo(一天到晚游泳的鱼)  是对的。
      

  4.   

    请问在SYBASE环境下的TOP应该改为什么呢