select * from 你的表 a
where Flag = '出货' and date in (select max(date) from 你的表 where matcode = a.matcode)Union allselect * from 你的表 a
where Flag = '收货' and date in (select max(date) from 你的表 where matcode = a.matcode)

解决方案 »

  1.   

    Select matcode, Max(date) as date, Flag From table
    Group by matcode, Flag
      

  2.   

    txlicenhe(马可) 的好像麻烦了点。
      

  3.   


    select a.*
    from tablename a join
         (  select matcode,[flag],max([date]) as md
            from tablename
            group by matcode,[flag]
         ) b
         on a.matcode=b.matcode and a.flag=b.flag and a.date=b.md
      

  4.   

    select * from 你的表 a
    WHERE a.date in
    (selecr max(date) from 你的表 where matcode = a.matcode)
      

  5.   

    我用中海的方法時,速度太慢了,在表中有一自動增長ID為rec_no,用下面語句即可取出哪些記錄出來,但不能取出其他字段來,能否用什麼辦法把記錄的 rec_no 給取出來,然後再 select * from stock_rec where rec_no in (select ....) 這樣呢?select matcode,[flag],max([date]) as md
            from tablename
            group by matcode,[flag]