select * from testtab
insert into testtab values('cd1', 1),('cd2', 1),('cd3', 1),('cd4', 1),('cd5', 1),('cd2', 2),('cd3', 2),('cd6', 2),('cd7', 2),('cd2', 3),('cd3', 3)
-- 这个是只查新建记录的数据 version=2 2是传参
select testtab.* from testtab join (select cd, count(version) as countv from testtab group by cd having count(version) = 1) tab1 on testtab.cd = tab1.cd where version = 2
-- 这个是只查发生过变更记录的数据 version in (2, 3) 2,3可以传一个参数或者两个参数
select testtab.* from testtab join (select cd, count(version) as countv from testtab group by cd having count(version) <> 1) tab1 on testtab.cd = tab1.cd where version in (2, 3)
网友评论