美文网首页
Having 数据分类

Having 数据分类

作者: 简陌刀丶阿吉 | 来源:发表于2022-03-24 15:42 被阅读0次
    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)
    

    相关文章

      网友评论

          本文标题:Having 数据分类

          本文链接:https://www.haomeiwen.com/subject/sltljrtx.html