A表中有记录如下:
a b c
1 bj jdk
2 bj dsf
3 zh kdd
4 dk jdk
5 bj did
现在要查询出b字段相同的记录出来,即查询结果为:
a b c
1 bj jdk
2 bj dsf
5 bj did
请问如何实现?
我的实现方式为:
select * from A where rowid!=(select max(rowid) from A u where A.b=u.b)
但这样,最后只能查出两条记录,最后一条没有出来.
方法:
select *
from A,
(
select b,count(*) rn
from A
group by b
) B
where A.b=B.b and rn>=2
或者
select a,b,c from (select a,b,c,count(*) over (partition by b) cnt
from tab) t
where cnt>1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8683736/viewspace-905705/ ,如需转载,请注明出处,否则将追究法律责任。