如例: select * from yourtable a where 时间=(select max(时间) from yourtable b where a.卡号=b.卡号)
select * from table1, (select 卡号,max(时间) from table1 group by 卡号)a where table1.时间=a.时间
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
select * from yourtable a where 时间=(select max(时间) from yourtable b where a.卡号=b.卡号)
where table1.时间=a.时间
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
from 表
group by 卡号