数据库原理及应用实验三参考答案
本题中所用的数据库是上次实验中所建立的Study数据库。请写出相应的查询语句。并将查询结果贴在下方。
- 查询所有同学的基本信息,包括:学号s_no、班级号class_no、姓名s_name、性别s_sex、出生日期s_birthday。
use Study;
select s_no,class_no, s_name, s_sex, s_birthday from Student
go
- 查询所有同学,要求显示其学号s_no、姓名s_name。
use Study;
select s_no,s_name from Student
go
- 查询所有男同学,要求显示其学号s_no、姓名s_name、出生日期s_birthday。
use Study;
select s_no,s_name,s_birthday from Student where s_sex='男'
go
- 查询所有出生日期在“1980-01-01”前的女同学,要求显示其学号s_no、姓名s_name、性别s_sex、出生日期s_birthday。
use Study;
select s_no,s_name,s_sex,s_birthday from Student where s_sex='女' and s_birthday < '1980-01-01'
go
- 查询所有姓“李”的男同学,要求显示其学号s_no、姓名s_name、性别s_sex、出生日期s_birthday。
use Study;
select s_no,s_name,s_sex,s_birthday from Student where s_sex='男' and s_name like '李%'
go
- 查询所有姓名中含有“一”字的同学,要求显示其学号s_no、姓名s_name。
use Study;
select s_no,s_name from Student where s_name like '%一%' go
- 查询所有职称不是“讲师”的教师,要求显示其教师号t_no、姓名t_name、职称t_title。
use Study;
select t_no,t_name,t_title from Teacher where t_title!='讲师'
go
- 查询虽选修了课程,但未参加考试的所有同学,要求显示出这些同学的学号s_no。
use Study;
select s_no from Choice where score is null
go
- 查询所有考试不及格的同学,要求显示出这些同学的学号s_no、成绩score,并按成绩降序排列。
use Study;
select s_no,score from Choice where score<60 order by score desc
go
- 查询出课程号为01001、02001、02003的所有课程,要求显示出课程号course_no、课程名称course_name。(要求用in运算符)。
use Study;
select course_no, course_score from Course where course_no in('01001','02001','02003')
go
- 查询所有在1970年出生的教师,要求显示其教师号t_no、姓名t_name、出生日期t_birthday。
use Study;
select t_no, t_name,t_birthday
from Teacher
where t_birthday between '1970-01-01'and'1970-12-31'
go
- 查询出选了课的学生的学号
use Study;
select distinct(s_no) from Choice
go
- 查询出各个课程号course_no及相应的选课人数。
use Study;
select course_no,count(course_no) from Choice
group by(course_no)
go
- 查询出教授两门以上课程的教师号t_no。
use Study;
select t_no from Teaching
group by(t_no) having count(course_no)>=2
go
- 查询出选修了01001课程的学生平均分数、最低分数及最高分数。
use Study;
select avg(score) as 平均分,min(score) as 最低分,max(score) as 最高分
from Choice
where course_no='01001'
go
- 查询1960年以后出生的,职称为讲师的教师的姓名t_name、出生日期t_birthday,并按出生日期升序排列。
use Study;
select t_name,t_birthday from Teacher where t_title='讲师' and t_birthday>='1961-01-01'
order by(t_birthday)
go
补充题目:
本题中所用的数据库是上次实验中所建立的Study数据库。请写出相应的查询语句。并将查询结果贴在下方。
(1)查询所有同学的选课及成绩情况,要求显示学生的学号s_no、姓名s_name、课程号course_no和课程的成绩score。
use Study
select Student.s_no,s_name,course_no,score
from Choice,Student
where Student.s_no = Choice.s_no
go
(2)查询所有同学的选课及成绩情况,要求显示学生的姓名s_name、课程名称course_ name、课程的成绩score,并将查询结果存放到一个新的数据表new_table中。
use Study
select s_name,course_name,score
into new_table
from Choice,Student,Course
where Student.s_no = Choice.s_no and Choice.course_no=Course.course_no
go
(3)查询“计算机99-1”班的同学的选课及成绩情况,要求显示学生的学号s_no、姓名s_name、课程号course_no、课程名称course_name、课程的成绩score。
use Study
select Student.s_no,Student.s_name,Course.course_name,Course.course_no,score
from Choice,Course,Student,Class
where
Choice.course_no=Course.course_no
and Student.s_no=Choice.s_no
and Student.class_no= Class.class_no
and class_name='计算机99-1'
go
(4)查询所有同学的学分情况(假设课程成绩≥60分时可获得该门课程的学分),要求显示学生的学号s_no、姓名s_name、总学分(将该列定名为:total_score)。(用JOIN)
use Study
select Choice.s_no,s_name,sum(course_score) as total_score
from Choice join Student on Choice.s_no = Student.s_no join Course on Choice.course_no = Course.course_no
where score>=60
group by s_name,Choice.s_no
go
(5)查询所有同学的平均成绩及选课门数,要求显示学生的学号s_no、姓名s_name、平均成绩(将该列定名为average_score)、选课的门数(将该列定名为:choice_num)。
use Study
select Student.s_no,s_name,avg(score) as average_score,count(course_no) as choice_num
from Student join Choice on Student.s_no = Choice.s_no
group by s_name,Student.s_no
go
(6)查询所有选修了课程但未参加考试的所有同学及相应的课程,要求显示学生的学号s_no、姓名s_name、课程号course_no、课程名称course_name。
use Study
select Student.s_no,s_name,Course.course_no,Course.course_name
from Student, Choice , Course
where Student.s_no =Choice.s_no and Choice.course_no =Course.course_no and score is null
go
(7)查询所有选修了课程但考试不及格(假设<60分为不及格)的所有同学及相应的课程,要求显示学生的学号s_no、姓名s_name、课程号course_no、课程名称course_name、学分course_score。
use Study
select Student.s_no,s_name,Course.course_no,course_name,course_score
from Choice,Student,Course
where Student.s_no = Choice.s_no and Choice.course_no=Course.course_no and score<60
go
(8)查询选修了课程名为“程序设计语言”的所有同学及成绩情况,要求显示学生的姓名s_name、课程的成绩score。(使用ANY)
use Study
select s_name, score
from Choice,Student,Course
where Student.s_no = Choice.s_no and Choice.course_no=any(select course_no from Course where course_name='程序设计语言')
go
(9)查询“计算机系”的所有同学及成绩情况,要求显示学生的学号s_no、姓名s_name、班级名称class_name、课程号course_no、课程名称course_name、课程的成绩score。
use Study
select Choice.s_no,s_name,Class.class_name,Choice.course_no,course_name,score from Choice,Student,Course,Class
where Choice.course_no = Course.course_no and Student.s_no = Choice.s_no and Class.class_no = Student.class_no and class_special = '计算机'
go
(10)查询所有教师的任课情况,要求显示教师姓名t_name、担任课程的名称course_name。
use Study
select t_name,course_name
from Course,Teaching,Teacher
where Teaching.course_no = Course.course_no and Teaching.t_no = Teacher.t_no
go
(11)查询所有教师的任课门数,要求显示教师姓名t_name、担任课程的门数(将该列定名为course_number)。
use Study
select Teacher.t_no,t_name,count(Course.course_no) as course_number
from Course,Teaching,Teacher
where Teaching.course_no = Course.course_no and Teaching.t_no = Teacher.t_no
group by Teacher.t_no, t_name
go
(12)查询和“李建国”是同一班级的同学的姓名。(使用子查询)
use Study
select s_name
from Student
where Student.class_no = (select class_no from Student where s_name='李建国') and s_name!= '李建国'
go
(13)查询没有选修“计算机基础”课程的学生姓名。(用NOT EXISTS)
use Study
select s_name
from Student
where not exists (select *
from Course,Choice
where Choice.course_no = Course.course_no and Student.s_no =Choice.s_no and course_name='计算机基础' )
go
(14)查询主讲“数据库原理与应用”和主讲“数据结构”的教师姓名。(用UNION)
use Study
select t_name
from Teacher,Teaching,Course
where Teacher.t_no= Teaching. t_no and Teaching.course_no = Course.course_no and Course.course_name = '数据库原理与应用'
union
select t_name
from Teacher,Teaching,Course
where Teacher.t_no= Teaching. t_no and Teaching.course_no = Course.course_no and Course.course_name = '数据结构'
go
(15)查询讲授了所有课程的教师的姓名。
use Study
select t_name
from Teacher
where not exists (select *
from Course
where not exists (select *
from Teaching
where Course.course_no = Teaching.course_no and Teacher.t_no = Teaching.t_no)
)
go
数据库原理及应用实验三参考答案相关推荐
- 数据库原理及应用实验二参考答案
一.实验内容及要求 1.创建数据库和数据表(在相应位置贴上SQL语句) (1)利用资源管理器,在D盘建立以自己的姓名为名称的文件夹,以便保存数据库. (2)登录并连接到SQL Server 服务器. ...
- 数据库原理及应用实验报告-实验8-参照完整性
数据库原理及应用实验报告 实验题目 实验8参照完整性 实验目的 学习建立外键,以及利用FOREIGN KEY-REFERENCES子句以及各种约束保证参照完整性. 实验内容 为演示参照完整性,建立表 ...
- c语言实验五函数答案,C语言程序设计实验五 参考答案.doc
C语言程序设计实验五 参考答案 实验5 函数(1)参考答案 5-1.以下程序的功能:从键盘输入两个数,计算出他们的和,并将结果输出在屏幕上.调试运行程序,观察出现了什么错误,提出修改方案. 答案: # ...
- c语言实验--九九乘法表,C语言程序设计实验四 参考答案.doc
实验四 参考答案 4-1.以下程序实现以直角三角形的形式在屏幕上输出九九乘法表,但实际输出结果如下.请查找原因,并调试程序以实现程序功能. 答案:正确程序: #include void main() ...
- 数据库原理与应用实验指导书 实验四:数据查询
数据库原理与应用 实验指导书 实验四:数据查询 一.实验目的 掌握SELECT语句的基本语法: 熟练掌握模糊查询的用法: 熟练掌握连接查询的用法: 熟练掌握子查询的用法. 二.实验内容 表数据的查询 ...
- 数据库原理与应用实验指导书 实验一:熟悉SQL Server 2012数据库管理系统
数据库原理与应用实验指导书 实验一:熟悉SQL Server 2012数据库管理系统 实验类型: 综合性 实验要求: 必修 适用对象: 信息管理与信息系统.计算机科学与技术.软件工程.物联网工程 一. ...
- 计算机网络实验考试西南交大,西南交大大学计算机基础实验2参考答案
西南交大大学计算机基础实验2参考答案 (20页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 14.90 积分 大学计算机基础实验报告大学计算机基础实验报告 ...
- 北理工计算机原理与应用实验,北理工计算机原理与应用实验三教程.docx
北理工计算机原理与应用实验三教程 本科实验报告 实验名称: 计算机原理与应用实验三 课程名称:计算机原理与应用实验时间:任课教师:实验地点:实验教师:实验类型:■ 原理验证□ 综合设计□ 自主创新学生 ...
- c语言实验11答案,c语言实验9-11参考答案
c语言实验9-11参考答案 (4页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 9.90 积分 数组 上机题9.编写程序:从键盘输入一串整数保存到数组中, ...
最新文章
- 生态物流的变革效应:左边资源、右边货源
- 浏览Github必备的5款神器级别的Chrome插件
- codechef INSQ15_A(hash+二分)
- Logisim 一个PLA电路
- php柱状图实现年龄分布,考官雅思写作小作文满分范文 柱状图:年龄分布
- 【Kubernetes】 configmaps is forbidden User system:anonymous cannot list resource configmaps
- python rpc调用_从0到1:全面理解 RPC 远程调用
- leetcode 1037. 有效的回旋镖(Valid Boomerang)
- Delphi循环语句 -For
- idea更改页面背景颜色设置为护眼颜色
- 人工智能在日常生活中的十大应用
- 【转载】用Pwnage + Redsnow 制作完美越狱固件
- 计算机二级excel高级筛选,Excel 如何按双条件执行高级筛选?
- 阿里云-视频点播服务API调用
- SAP中用户上传附件出错处理实例
- linux中一次显示一页内容的命令
- CLion: rsync is not installed or not avaiable in PATH on remote host
- AGM FPGA与CPLD烧录说明
- /etc/profile文件简单介绍
- 计算机音乐制作手册,计算机音乐制作手册