ORACLE SQL语句查询一个字段在另一表字段中有两条或以上 的数据

 我来答
刺任芹O
2022-11-16 · TA获得超过6.1万个赞
知道顶级答主
回答量:38.7万
采纳率:99%
帮助的人:8013万
展开全部

1、创建两张测试表,

create table test_student(student_id varchar2(20), student_name varchar2(20));

create table test_class(student_id varchar2(20), class_id varchar2(20));

2、插入测试数据

insert into test_student values(1001,'陈XX');

insert into test_student values(1002,'许XX');

insert into test_student values(1003,'张XX');

insert into test_student values(1004,'吴XX');

insert into test_class values (1001,'C01');

insert into test_class values (1001,'C02');

insert into test_class values (1002,'C01');

insert into test_class values (1003,'C01');

insert into test_class values (1004,'C01');

insert into test_class values (1004,'C02');

3、查询表的记录,select t.*, rowid from test_class t;

4、编写sql,查询出来test_student表中在test_class表中是多条而不是单条的记录,可以看到1001、1004学生是有多条记录的,

select t.student_id, 

       count(1) a

  from test_student t , test_class b

 where t.student_id = b.student_id

 group by t.student_id

 having count(*)>1,

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式