34,594
社区成员
发帖
与我相关
我的任务
分享
select aa.* from (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)aa where not exists( select 1 from (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)bb where aa.cardid=bb.cardid and aa.effdate<bb.effdate)
select a.id,a.cardid,b.company
from t1 a join t2 b on a.id = b.id
where not exists (select 1 from t2 where effdate > b.effdate)
--不过这个效率不高!
select a.id,a.cardid,b.company
from t1 a,
(select company from t2 b where not exists (select 1 from t2 where effdate > b.effdate)) b
--or
select a.id,a.cardid,b.company
from t1 a,
(select top 1 company from t2 order by effdate desc) b
select aa.* (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)aa where not exists( select 1 from (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)bb where aa.cardid=bb.cardid and aa.effdate<bb.effdate)
select a.id,a.cardid,b.company
from T1 a,T2 b where a.id = b.id
and not exists (select 1 from T2 where cardid= b.cardid and effdate > b.effdate)
select a.* (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)aa where not exists( select 1 from (select a.id,cardid,company,effdate from T1,T2 a where T1.id=T2.id)bb where aa.cardid=bb.cardid and aa.effdate<bb.effdate)
select a.*
(select a.id,cardid,company,effdate
from T1,T2 a
where T1.id=T2.id)aa where not exists( select (select a.id,cardid,company,effdate
from T1,T2 a
where T1.id=T2.id)bb where aa.cardid=bb.cardid and aa.effdate<bb.effdate)
select a.id,a.cardid,b.company
from T1 a,T2 b where a.id = b.id
and not exists (select 1 from T2 where id = b.id and effdate > b.effdate)
select a.id,a.cardid,b.company
from t1 a join t2 b on a.id = b.id
where not exists (select 1 from t2 where id = b.id and effdate > b.effdate)