sql语句查询没有被学生选修过的课程(即课程号没有在sc表中出现过)的名称.

如题所述

第1个回答  2022-12-11

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

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网