select num from table where cast(DateFaSheng as char(10))+ MaterCode in (select cast(max(DateFaSheng) as char(10))+ MaterCode from table group by DateFaSheng,MaterCode)

解决方案 »

  1.   

    create table t(Num int,DateFaSheng datetime,MaterCode varchar(20))
    insert t select 3,'2007-04-25','120101001'
    union all select 8,'2007-04-27','120101001'
    union all select 13,'2007-05-01','120101001'
    union all select 8,'2007-05-06','124301001'
    union all select 8,'2007-05-12','124301001'select * from t a where not exists
    (
      select 1 from t where MaterCode=a.MaterCode and DateFaSheng>a.DateFaSheng
    )Num         DateFaSheng                                         MaterCode            
    ----------- ------------------------------------------------------ ------------------
    13          2007-05-01 00:00:00.000                                120101001
    8           2007-05-12 00:00:00.000                                124301001(所影响的行数为 2 行)