日期:2014-05-18  浏览次数:20524 次

同表比较
A表
cardid time cade defrr degds
10 2010-10-12 23:05:06 ds s34 dfe
10 2010-10-11 23:06:06 das s344 dfwwe
12 2010-10-10 20:05:06 dds s34 ddsfe
13 2010-10-12 21:05:06 dees s3ff4 dfdfe
145 2010-10-15 23:05:06 dggs s3554 dflke
145 2010-10-15 11:05:06 dhhs s3jj4 dfrre
561 2010-10-12 23:05:06 djjs s3jj4 dfgte


结果如下
cardid time cade defrr degds
10 2010-10-12 23:05:06 ds s34 dfe
12 2010-10-10 20:05:06 dds s34 ddsfe
13 2010-10-12 21:05:06 dees s3ff4 dfdfe
145 2010-10-15 23:05:06 dggs s3554 dflke
561 2010-10-12 23:05:06 djjs s3jj4 dfgte


我的A表中有1000多万条数据,求怎么快捷的可以筛选出我想要的那种结果!

------解决方案--------------------
SQL code

select *
from tb t
where not exists (select 1 from tb where cardid = t.cardid and time > t.time)

------解决方案--------------------
SQL code
select * from A t where time=(select max(time) from A where cardid=t.cardid)