select * from 表 t1,(select 卡号,max(时间) as 时间 from 表 group by 卡号) t2
where t1.卡号=t2.卡号 and t1.时间=t2.时间

解决方案 »

  1.   

    如例:
    select * from yourtable a where 时间=(select max(时间) from yourtable b where a.卡号=b.卡号)
      

  2.   

    select * from table1, (select 卡号,max(时间) from table1 group by 卡号)a
    where table1.时间=a.时间
      

  3.   

    create table card(
    cardid varchar(10),
    name varchar(100),
    cost money,
    time datetime
    )
    goinsert into card values('10001','卡1',20.00,'2004-1-17 13:50:00')
    insert into card values('10001','卡1',24.00,'2004-1-18 16:02:00')
    insert into card values('20001','卡2',102.00,'2004-1-15 14:50:00')
    insert into card values('20001','卡2',80.00,'2004-1-21 6:50:00')
    insert into card values('20001','卡2',53.00,'2004-1-23 3:12:00')
    insert into card values('30001','卡3',33.00,'2004-1-15 14:50:00')--测试
    select * from card a 
    where 
    a.time =(select max(time)
    from card b 
    where a.cardid=b.cardid
    )
    order by cardid
      

  4.   

    select distinct 卡号,max(时间)
    from 表 
    group by 卡号