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. 如何实现python连续输入

    题型:输入矩阵,求对角线之和 思路(模型): i=0 while i<3: x=input() i+=1 print(x) 可以实现输入三行,最后输出最后一个x x=int(input()) m ...

  2. oracle Data Modeler 使用教程

    由于 powerdesigner 的版权问题.公司要求集体换成 oracle Data Modeler .免费版就够用,哈哈.这有很详细的入门教程,看一看吧: 官方正版教程 ,特详细,只是英文的,也只 ...

  3. SQL语句完整的执行顺序(02)

    这是对SQL语句完整的执行顺序(01)的补充: 数据库是mysql,使用的数据库表名称是my_student. 表的完整数据信息是: 完整语法是: Select [select选项] 字段列表[字段别 ...

  4. 基于Vue2.x的小米商城移动端项目

    初学vue已经有一段时间,为了检验自己的学习成果,决定做一个项目作为一个阶段性总结,项目花了差不多半个月时间,目前实现了7个页面,商城的主要功能基本实现,代码已经放到github上面. 这个项目把大部 ...

  5. js中数组对象去重的方法

    var arr = [{ key: '01', value: '乐乐' }, { key: '02', value: '博博' }, { key: '03', value: '淘淘' },{ key: ...

  6. JS 从剪贴板上传图片

    用Ubuntu两年多了,习惯了Ubuntu的操作感觉比WIN用起来还爽,就一点不爽,生态应用很少,好多WIN上好用的软件在Ubuntu找不到的,希望以后的软件可以做到一次编译全平台通用. 即使用上Wi ...

  7. VIM系统复制粘贴

    1 需求 系统复制粘贴主要是满足下面两个需求. 在多个对象之间复制粘贴 vim窗口与vim窗口之间 外部界面与vim窗口之间 不变复制粘贴.从外部界面复制粘贴到vim窗口时,文本不发生任何变化. 2 ...

  8. 前端如何做好seo

    一:什么是SEO? 搜索引擎优化(Search Engine Optimization),简称SEO.是按照搜索引擎给出的优化建议,以增强网站核心价值为目标,从网站结构.内容建设方案.用户互动传播等角 ...

  9. 微服务框架——SpringCloud(四)

    1.Spring Cloud Config 分布式配置 a.Config服务器 ①新建springboot项目,依赖选择Config Server ②pom文件关键依赖 <parent> ...

  10. 福州大学软件工程1916|W班 第6次作业成绩排名

    作业链接 团队第三次-项目原型设计 评分细则 博客评分标准 在随笔开头,备注小组同学的学号.(1') 文字准确.样式清晰.图文并茂.字数在1000字左右.(10') 原型模型必须采用专用的原型模型设计 ...