select md001 as 品号,md002 as 单价, md003 as 日期 from 表
一个品号可能存在不同日期的多比单价,我要找寻日期最大的(日期的格式为20110704) 

解决方案 »

  1.   

    select md001 as 品号,
          md002 as 单价, 
          md003 as 日期 
    from 表
    where md003 in (select max(a.md003) from 表 a  where a.md001 =md001 )
      

  2.   

    select * from tb t where date=(select max(date) from tb where md001=t.md001)
      

  3.   

    ;with t as
    (
      select rn=row_number()over(partition by md001 order by md003 desc),* from tb
    )
    select md001 as 品号,md002 as 单价,md003 as 日期 from t where rn=1 
      

  4.   


    select md001 as 品号,md002 as 单价,md003 as 日期 from #tb as t1
    where not exists(select 1 from #tb as t2 where t2.md001=t1.md001 and t2.md003>t1.md003 )
      

  5.   

    select * from tb t where date=(select max(date) from tb where md001=t.md001
      

  6.   

    select * from tb t where date=(select max(date) from tb where md001=t.md001)