请问,怎么样取得两个字段都重复的记录

kill_jp 2005-01-05 06:32:29
我想取得表中a_class,a_name两个字段都重复的记录
例如取得如下的记录:a_id是自增值

a_id,a_class,a_name
1 1 111
2 1 111


像上面的两条记录,a_class,a_name两个字段都重复,怎样取得?
多谢各位大侠!不胜感激!!!
...全文
197 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zh430 2005-01-06
  • 打赏
  • 举报
回复
就是分组了,然后查每组的记录数,大于1的就是重复的了
GerryYang 2005-01-06
  • 打赏
  • 举报
回复
select * from a where (a_class,a_name) in
( select a_class,a_name from 表
group by a_class,a_name
having count(1)>1
)
ATGC 2005-01-05
  • 打赏
  • 举报
回复
诶,原来楼主是要显示所有的符合条件的记录数大于等于2的
ORARichard 2005-01-05
  • 打赏
  • 举报
回复
select a.* from 表 a,
(
select a_class,a_name from 表
group by a_class,a_name
having count(1)>1
) b
where a.a_class=b.a_class and a.a_name=b.a_name;
ORARichard 2005-01-05
  • 打赏
  • 举报
回复
select * from 表 a,
(
select a_class,a_name from 表
group by a_class,a_name
having count(1)>1
) b
where a.a_class=b.a_class and a.a_name=b.a_name;
NinGoo 2005-01-05
  • 打赏
  • 举报
回复
select a_class,a_name
from table
group by a_class,a_name
having count(*)>1

-结果

a_class a_name
----------- -----------
1 111

(所影响的行数为 1 行)


不知楼上的有没有明白结果是怎样的?呵呵
frenchletter 2005-01-05
  • 打赏
  • 举报
回复
select a_class,a_name
from table
group by a_class,a_name
having count(*)>1

这个显然好得多
至少我一看就明白
NinGoo 2005-01-05
  • 打赏
  • 举报
回复
--测试数据
a_id a_class a_name
----------- ----------- -----------
1 1 111
2 1 111
3 1 112


--测试结果
a_id a_class a_name
----------- ----------- -----------
1 1 111
2 1 111

(所影响的行数为 2 行)
NinGoo 2005-01-05
  • 打赏
  • 举报
回复

select a.* from t1 a,t1 b
where a.a_id<>b.a_id and a.a_class=b.a_class and a.a_name=b.a_name
order by a.a_id


ATGC 2005-01-05
  • 打赏
  • 举报
回复
select a_class,a_name
from table
group by a_class,a_name
having count(*)>1

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧