欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle 查询两个字段值相同的记录

程序员文章站 2022-05-29 09:47:58
select A.* from tb_mend_enrol A, (select A.Typeid, A.address from tb_mend_enrol A group by A.Typeid, A.address having count(A.Typeid) >= 2 and count(A ......
select a.* from tb_mend_enrol a,
                (select a.typeid, a.address from tb_mend_enrol a
                  group by a.typeid, a.address
                  having count(a.typeid) >= 2 and count(a.address) >= 2 ) b
where a.typeid = b.typeid  and a.address = b.address and a.reporter='测试' 
and a.reptime >= to_date('2018-08-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
order by a.address, a.reptime


方法二:

select a.* from tb_mend_enrol a
where (select count(*) from tb_mend_enrol a1
where a1.typeid = a.typeid and a1.address=a.address)>1
and a.reporter='测试'
and a.reptime >= to_date('2018-08-01 00:00:00','yyyy-mm-dd hh24:mi:ss'
order by a.address