50分求一条oracle的SQL语句

来源:百度知道 编辑:UC知道 时间:2024/05/12 10:42:50
表a
code user
01 小猪
02 小狗

表b
code teching
01 语文
01 数学
01 物理
02 英语
02

现在我要用一条SQL语句把已经安排完课程的记录提出来(就是应该把01这1条记录提出来)
要求:结果集只有1条记录
我的意思是用一条SQL语句把已经安排完课程记录的动物的记录提出来,用表a的记录去关联表b的记录,大概要用到left join之类的
简单一点就是想知道有几个动物课程已经安排完了

select 表a.code
from 表a,表b
where 表a.code = 表b.code
group by 表a.code
having count(表b.code)>=3

同意,golongfly

select * from user
where code not in (select code from b where teching is null)

“已经安排完课程的记录”
这个定义不清楚的
sql怎么写?

select distinct a.code from a, b
where b.teching is not null and a.code=b.code