select * from 表 a
where not exists(
    select * from 表
    where 货号=a.货号 and 时间<a.时间)

解决方案 »

  1.   

    这样取得的结果集是每个货号的时间排正序后的第一条记录,我试着在语句最后加了 order by 时间 desc,显示的结果集还是一样,怎么回事?我需要取按时间排倒序后取每一个货号的第一条记录
      

  2.   

    select * from 表 a
    where not exists(
        select * from 表
        where 货号=a.货号 and 时间>a.时间)  -- 看错了, 正序用小于, 倒序用大小即可.