当前位置:网站首页>数据库上机实验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>80
4、查询姓张的学生的学号、姓名和专业班级。
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 null
6、查询选修了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、子查询要有括号括起来。
边栏推荐
- C语言教程(三)-if和循环
- 对list集合进行分页,并将数据显示在页面中
- 限流的原理
- 110 MySQL interview questions and answers (continuously updated)
- Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
- What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
- 剑指offer基础版 ----- 第28天
- 数据集划分以及交叉验证法
- Kubernetes 证书可用年限修改
- a different object with the same identifier value was already associated with the session
猜你喜欢
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
剑指offer基础版 ---- 第26天
面试官,不要再问我三次握手和四次挥手
Lock wait timeout exceeded解决方案
MySQL transaction isolation level, rounding
一文了解大厂的DDD领域驱动设计
SQL injection of DVWA
Unity mobile game performance optimization series: performance tuning for the CPU side
The interviewer asked me TCP three handshake and four wave, I really
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
随机推荐
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
pycharm专业版使用
CentOS7 install MySQL graphic detailed tutorial
Centos7 install mysql5.7 steps (graphical version)
Simple command of mysql
如何将项目部署到服务器上(全套教程)
面试官,不要再问我三次握手和四次挥手
有了MVC,为什么还要DDD?
.NET-6.WinForm2.NanUI learning and summary
基于web3.0使用钱包Metamask的三方登陆
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
工作流编排引擎-Temporal
Mysql——字符串函数
数据库学习笔记
剑指offer基础版 --- 第22天
12 reasons for MySQL slow query
Kubernetes 证书可用年限修改
剑指offer基础版 ----第31天
一文了解大厂的DDD领域驱动设计