ITPub博客

首页 > 数据库 > 数据库开发技术 > 查询重复记录问题

查询重复记录问题

原创 数据库开发技术 作者:kendyhxl 时间:2007-03-18 18:04:16 0 删除 编辑

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

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8683736/viewspace-905705/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: oracle 基本知识
下一篇: Oracle初级教程
请登录后发表评论 登录
全部评论
  • 博文量
    21
  • 访问量
    47655