当前位置:网站首页>数据库上机实验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、子查询要有括号括起来。
边栏推荐
猜你喜欢

面试官问我TCP三次握手和四次挥手,我真的是
![[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade](/img/af/7a2cdcc6535c04c508c9ddf9ee0cb2.png)
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade

剑指offer基础版 ---- 第27天

Why use Flink and how to get started with Flink?

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

面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式

Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?

Multiple table query of sql statement

基于web3.0使用钱包Metamask的三方登陆

MySQL_关于JSON数据的查询
随机推荐
剑指offer基础版 ---- 第29天
精解四大集合框架:List 核心知识总结
What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
The interviewer asked me TCP three handshake and four wave, I really
Summary of MySQL common interview questions (recommended collection!!!)
如何将项目部署到服务器上(全套教程)
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
Redis的初识
剑指offer基础版 ----- 第28天
tf.keras.utils.get_file()
Minesweeper game (written in c language)
Object Detection Study Notes
Temporal线上部署
Linux系统安装mysql(rpm方式安装)
DVWA shooting range environment construction
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
ABC D - Distinct Trio (Number of k-tuples
分布式事务——分布式事务简介、分布式事务框架 Seata(AT模式、Tcc模式、Tcc Vs AT)、分布式事务—MQ
【一起学Rust】Rust学习前准备——注释和格式化输出