SQL语句题

Student(Sno,Sname,Sage,Ssex)注释:学生表(学号,姓名,性别年龄,性别)

Course(Cno,Cname,Tno) 注释:课程表(课程号,课程名称,教师编号)

SC(Sno,Cno,score) 注释:成绩表(学号,课程号,成绩)

Teacher(Tno,Tname)注释:教师表(教师编号,教师名)

drop sequence  s_student;

create sequence s_student;

drop table student cascade constraint purge;

create table Student(

Sno number primary key,

Sname varchar(30),

Sage number(3),

Ssex char(1)

);

insert into Student values(s_student.nextval,'张三1',21,'m');

insert into Student values(s_student.nextval,'张三2',22,'m');

insert into Student values(s_student.nextval,'张三3',23,'w');

insert into Student values(s_student.nextval,'张三4',24,'m');

commit;

drop sequence  s_teacher;

create sequence s_teacher;

drop table teacher cascade constraint purge;

create table Teacher(

Tno number primary key,

Tname  varchar(30)

);

insert into teacher values(s_teacher.nextval,'里老师1');

insert into teacher values(s_teacher.nextval,'张三');

insert into teacher values(s_teacher.nextval,'里老师3');

insert into teacher values(s_teacher.nextval,'里老师4');

commit;

成绩

drop table sc cascade constraint purge;

create table SC(

Sno number constraint sc_sno_fk references student(sno),

Cno number constraint sc_cno_fk references course(cno),

score number,

constraint sc_sno_cno_pk primary key(sno,cno)

) ;

insert into sc values(1,2,58);

insert into sc values(2,4,21);

insert into sc values(3,3,76);

insert into sc values(4,1,50);

insert into sc values(2,1,66);

insert into sc values(1,3,20);

insert into sc values(2,2,30);

insert into sc values(3,2,50);

insert into sc values(4,4,55);

commit;

课程

drop sequence s_course;

create sequence s_course;

drop table course cascade constraint purge;

create table Course(

Cno number primary key,

Cname varchar(30),

Tno number constraint course_tno_fk references teacher(tno)

);

insert into course values(s_course.nextval,'java',1);

insert into course values(s_course.nextval,'javascript',2);

insert into course values(s_course.nextval,'jdbc',3);

insert into course values(s_course.nextval,'hibernate',4);

commit;

1、查询每个学生的学号,姓名,所修课程及成绩;

select * from student st join sc s on st.sno=s.sno join course co on co.cno=s.cno;

2、查询学过“001”或者学过编号“002”课程的同学的学号、姓名;

非关联子查询

select * from student where sno in (select sno from course where cno=2 or cno=1);

关联子查询

select * from student s where exist (select 1 from course c where s.sno=c.sno and (cno=1 or cno=2));

3、将课程号为“002”的授课老师改为“张三”;

update course set tno=(select tno  from teacher where tname='张三') where cno=4;

4、向SC表中插入一条记录,学号001,课程号003,成绩80;

delete from sc where sno=2 and cno=1;

5、删除“002”同学的“001”课程的成绩;

delete from sc where cno=1 and sno=4;

6、查询不及格的课程,并按课程号从大到小排列;

select score , cno  from  sc where score<60 order by cno desc;

7、查询两门以上不及格课程的同学的学号及其平均成绩;

select sno  , avg(score) from sc

where score<60  group by sno having count(sno)>=2;

8、查询姓“李”的老师的姓名及授课情况;

select * from teacher t join course c on t.tno=c.tno where tname like '张%';

9、统计每门课程的学生选修人数(超过10人的课程才统计),要求输出课程号和选修人数查询结果按人数降序排序,若人数相同,按课程号升序排序;

select cno,count(cno) ,max(cname)

from(

select c.cno ,c.cname from sc s

join course c on s.cno=c.cno

)

group by cno

having count(cno)>1

order by cno desc;

10、统计列印各科成绩,各分数段人数:课程ID,课程名称[100-85],[85-70],[70-60],[<60]

select cname||'[85-100]' name,score,c.cno

from sc s  join course c on s.cno=c.cno where score between 85 and 100

union

select cname||'[70-85]' name,score,c.cno

from sc s  join course c on s.cno=c.cno where score between 70 and 85

union

select cname||'[60-70]' name,score,c.cno

from sc s  join course c on s.cno=c.cno where score between 60 and 70

union

select cname||'[<60]' name,score,c.cno

from sc s  join course c on s.cno=c.cno where score<60

SQL语句题的更多相关文章

  1. SQL语句题库

    一.    填空题 Not Only SQL数据库 泛指  非关系型数据库  . SYS和SYSTEM用户都是Oracle 的系统用户,它们都使用SYSTEM表空间,其中 sys 拥有更大的权限. O ...

  2. 50道 Sql语句题

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表   ...

  3. sql语句练习50题(Mysql版-详加注释)

    表名和字段 1.学生表       Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别 2.课程表       Course(c_id, ...

  4. SQL语句50题

    -- 一.创建教学系统的数据库,表,以及数据 --student(sno,sname,sage,ssex) 学生表--course(cno,cname,tno) 课程表--sc(sno,cno,sco ...

  5. sql语句练习50题(Mysql版)

    表名和字段–1.学生表Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别–2.课程表Course(c_id,c_name,t_id) – ...

  6. 经典SQL语句基础50题

    很全面的sql语句大全.都是很基础性的,今天特意整理了下.大家互相学习.大家有好的都可以分享出来,  分享也是一种快乐. --创建数据库 create database SQL50 --打开SQL50 ...

  7. -sql语句练习50题(Mysql学习练习版)

    –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id,c_name,t_id) – –课 ...

  8. sql语句练习50题(Mysql版) 围观

    表名和字段 –.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –.课程表 Course(c_id,c_name,t_id) ...

  9. MySQL经典练习题及答案,常用SQL语句练习50题

    表名和字段 –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id,c_name,t_id ...

随机推荐

  1. spring security5.0源码导入idea

    资源路径:链接:https://pan.baidu.com/s/1Xep6hzyIF2a0AtFYDeO_bw提取码:6af8 1.解压源码 2.编译源码     windows下:直接双击gradl ...

  2. 初学python之路-day06

    每天一篇总结,今天学习了大概有深浅拷贝,元组类型,字典类型与集合类型.第一次感觉有点难度,需要花费多点时间来掌握. 深浅拷贝,分为值拷贝.浅拷贝.深拷贝. ls = [1, 'abc', [10]] ...

  3. html如何实现圆角的百度搜索框?

    <form action="http://www.baidu.com/baidu" target="_blank"> <input type= ...

  4. Mac 小功能

    Safari  安装扩展    https://safari-extensions.apple.com/?category=translation 关闭第三方验证  有时候打开自己下载的安装包会提示 ...

  5. About Why Inline Member Function Should Defined in The Header File

    About why inline member function should defined in the header file. It is legal to specify inline on ...

  6. 《ServerSuperIO Designer IDE使用教程》-4.增加台达PLC驱动及使用教程,从0到1的改变。发布:v4.2.3版本

    v4.2.3 更新内容:1.优化数据存储部分,提高效率.2.修复数据库服务停止造成程序异常退出的现象.3.修复本机没有串口造成无法增加设备驱动的情况.4.增加编辑设备和监测点配置信息功能.5.增加台达 ...

  7. Spring cloud定义学习

    今天讲到的最重要的内容: Spring cloud是什么? Spring cloud项目 spring cloud版本     什么事springcloud? spring cloud 为开发人员提供 ...

  8. tensorflow RNN循环神经网络 (分类例子)-【老鱼学tensorflow】

    之前我们学习过用CNN(卷积神经网络)来识别手写字,在CNN中是把图片看成了二维矩阵,然后在二维矩阵中堆叠高度值来进行识别. 而在RNN中增添了时间的维度,因为我们会发现有些图片或者语言或语音等会在时 ...

  9. Codeforces 446A. DZY Loves Sequences (线性DP)

    <题目链接> 题目大意: 给定一个长度为$n$的序列,现在最多能够改变其中的一个数字,使其变成任意值.问你这个序列的最长严格上升子段的长度是多少. #include <bits/st ...

  10. ABC113 AK失败记

    众所周知, ABC是一场水题盛宴, 也是一场AK盛宴. 但是我却没能AK. 原因也十分可笑: 我在一开始觉得题目太简单, 颓废了.直到我看了第4题之后才找到状态并A了此题...最后时间来不及第三题最后 ...