id   编号(mid)  时间 time
1     001   2009-12-3
2     002   2009-12-3
3     003   2009-12-3
4     004   2009-12-3
5     001   2009-12-3
6     002   2009-12-3
7     003   2009-12-3
8     004   2009-12-3
9     001   2009-12-3
10    002   2009-12-3
11    003   2009-12-3
12    001   2009-12-3
13    003   2009-12-3
14    004   2009-12-3

解决方案 »

  1.   

    select *
    from yourTable a
    where not exists (select 1 from yourTable where 编号=a.编号 and 时间>a.时间)
      

  2.   

    select a.* from tt a
    inner join
    (select  编号,max(time) as ma from tt ) b
    on a. 编号=b. 编号 and a.time=b.ma
      

  3.   

    不好用,我要的是某一编号的最后一条记录
    该语句
    select *
    from yourTable a
    where not exists (select 1 from yourTable where 编号=a.编号 and 时间>a.时间)
    查的是所有 的啊
      

  4.   

    本帖最后由 ACMAIN_CHM 于 2009-12-03 11:57:27 编辑
      

  5.   

    呵呵,没有说明按照ID取
    select a.* from tt a 
    inner join 
    (select  编号,max(id) as ma from tt ) b 
    on a. 编号=b. 编号 and a.id=b.ma