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

CentOS7 - yum install mysql
![【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试](/img/7a/c70077c7a95137aaeb49c344c82696.png)
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试

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

MySQL8.0.26安装配置教程(windows 64位)

Mysql application cannot find my.ini file after installation

SQL injection of DVWA

面试官:生成订单30分钟未支付,则自动取消,该怎么实现?

剑指offer基础版 ---- 第29天
![[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

面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
随机推荐
Temporal介绍
Flink sink ES 写入 ES(带密码)
Minesweeper game (written in c language)
Input length must be multiple of 8 when decrypting with padded cipher
Object Detection Study Notes
三次握手与四次挥手
Minio upload file ssl certificate is not trusted
docker安装postgresSQL和设置自定义数据目录
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
剑指offer专项突击版 --- 第 3 天
Reference code series_1. Hello World in various languages
CentOS7 - yum install mysql
A complete introduction to JSqlParse of Sql parsing and conversion
账号或密码多次输入错误,进行账号封禁
Three handshakes and four waves
Three oj questions on leetcode
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
STM32——DMA
torch.normal function usage
torch.normal函数用法