如题所述
1、创建学生及课程表,
create table test_student(stu_id number, class_id number);
create table test_class(class_id number, class_name varchar2(30));
2、插入测试数据,
insert into test_student values(1,1001);
insert into test_student values(2,1001);
insert into test_student values(3,1002);
insert into test_student values(4,1003);
insert into test_student values(5,1003);
insert into test_student values(6,1003);
insert into test_class values(1001,'美术');
insert into test_class values(1002,'音乐');
insert into test_class values(1003,'绘画');
insert into test_class values(1004,'跆拳道');
3、查询学生选修的课程,
select * from test_student t, test_class b where t.class_id = b.class_id
4、查询无学生选修的课程,可以发现1004 跆拳道课程,无人选择,
select b.*
from test_student t, test_class b
where t.class_id(+) = b.class_id
and t.class_id is null