当前位置:网站首页>数据库上机实验2 单表查询和嵌套查询
数据库上机实验2 单表查询和嵌套查询
2022-07-31 05:09:00 【Meteor.792】
一、实验目的
1、熟练掌握Select子句中各种用法。
2、熟练掌握Where子句中各种运算符的使用方法。
3、掌握各种嵌套查询的使用方法。
二、实验内容
根据实验1中创建的学生作业管理数据库以及其中的学生表、课程表和学生作业表,进行以下的查询操作(每一个查询都要给出SQL语句,列出查询结果)。
1、查询学时数大于60的课程信息。
select * from course where stime>60
2、查询在1986年出生的学生的学号、姓名和出生日期。
select sno,sname,birth from student where birth like '1986%'3、查询三次作业的成绩都在80分以上的学号、课程号。
select sno,cno from score where cj1>80 and cj2>80 and cj3>804、查询姓张的学生的学号、姓名和专业班级。
select sno,sname,major from student where sname like '张%'5、查询没有作业成绩的学号和课程号。
select sno,cno from score where cj1 is null or cj2 is null or cj3 is null6、查询选修了K001课程的学生人数。
select count(*) from score where cno='K001'7、查询与“张志国”同一班级的学生信息(使用子查询方式)。
select * from student
where major=(select major from student where sname='张志国')
8、查询比“计算机应用基础”学时多的课程信息(使用子查询方式)。
select * from course
where stime>(select stime from course where cname='计算机应用基础')9、查询选修课程号为K002的学生的学号、姓名(使用exists关键字的相关子查询)。
select sno,sname from student
where exists(select sno from score where student.sno=score.sno and cno='K002')10、查询没有选修K001和M001课程的学号、课程号和三次成绩(使用子查询方式)。
select sno,cno,cj1,cj2,cj3 from score
where cno not in(select cno from score where cno='K001' or cno='M001')三、实验指导
1、启动SQL Server2012软件。
2、通过分离附加的方法,将实验1所创建的作业管理数据库恢复到该软件中。
3、SQL Server中,程序不区别大小写,特别要注意程序中的标点符号,一定要在英文半角状态下输入,否则会出错。
4、注意通配符的使用方法,%匹配0个或多个字符,_匹配单个字符。
5、注意运算符的优先级,算术运算符优于比较运算符,比较运算符优于逻辑运算符,逻辑运算符的优先级是非、与、或。
6、判断某个列是否为空值是:列名 is null,而不是:列名=null。
7、子查询要有括号括起来。
边栏推荐
猜你喜欢

剑指offer专项突击版 ---- 第 6 天

DVWA installation tutorial (understand what you don't understand · in detail)

The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays

Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode

Lock wait timeout exceeded解决方案

ES source code API call link source code analysis

剑指offer专项突击版 ---- 第1天
![[mysql improves query efficiency] Mysql database query is slow to solve the problem](/img/fa/502a2efdd37508f15541558851a254.png)
[mysql improves query efficiency] Mysql database query is slow to solve the problem

MySQL-Explain详解

matlab abel变换图片处理
随机推荐
数据集划分以及交叉验证法
C语言教程(二)-printf及c自带的数据类型
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
Temporal客户端模型
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
Why use Flink and how to get started with Flink?
ABC D - Distinct Trio (Number of k-tuples
.NET-6.WinForm2.NanUI learning and summary
Anaconda configure environment directives
docker安装postgresSQL和设置自定义数据目录
剑指offer基础版 --- 第24天
【LeetCode-SQL每日一练】——2. 第二高的薪水
目标检测学习笔记
Pytorch教程Introduction中的神经网络实现示例
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
1. Get data - requests.get()
【MQ我可以讲一个小时】
MySQL transaction isolation level, rounding
Unity Framework Design Series: How Unity Designs Network Frameworks
Reference code series_1. Hello World in various languages