日期:2014-05-18 浏览次数:20588 次
create table tbl_person(pid int,pmoney money) insert into tbl_person values(1,200) insert into tbl_person values(2,0) insert into tbl_person values(3,300) create table tbl_person_list(lid int identity(1,1),pid int,lmoney money,pmoney money,ldate datetime) insert into tbl_person_list values(1,50,50,'2008-2-11') insert into tbl_person_list values(2,50,50,'2008-2-11') insert into tbl_person_list values(3,50,50,'2008-2-11') insert into tbl_person_list values(1,50,100,'2008-2-13') insert into tbl_person_list values(2,-56,-6,'2008-2-13') insert into tbl_person_list values(3,100,150,'2008-2-13') insert into tbl_person_list values(1,100,200,'2008-2-14') insert into tbl_person_list values(3,150,300,'2008-2-14') select a.* from tbl_person a inner join (select * from tbl_person_list a where not exists( select 1 from tbl_person_list where pid=a.pid and ldate>a.ldate))b on a.pid=b.pid and a.pmoney<>b.pmoney pid pmoney ----------- --------------------- 2 0.00 (1 行受影响)