当前位置:网站首页>数据库上机实验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、子查询要有括号括起来。
边栏推荐
- 有了MVC,为什么还要DDD?
- Linux系统安装mysql(rpm方式安装)
- Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
- Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
- Temporal线上部署
- C语言的文件操作(一)
- 面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
- 面试官问我TCP三次握手和四次挥手,我真的是
- MySQL-Explain详解
- matlab abel变换图片处理
猜你喜欢
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
110 MySQL interview questions and answers (continuously updated)
为什么要用Flink,怎么入门使用Flink?
工作流编排引擎-Temporal
剑指offer基础版 --- 第24天
Distributed transaction processing solution big PK!
1. Get data - requests.get()
mysql uses on duplicate key update to update data in batches
mysql5.7.35安装配置教程【超级详细安装教程】
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
随机推荐
剑指offer基础版 ---- 第27天
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
MySQL8--Windows下使用压缩包安装的方法
TOGAF之架构标准规范(一)
numpy和pytorch中的元素拼接操作:stack,concatenat,cat
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
Numpy中np.meshgrid的简单用法示例
MySQL(更新中)
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Flink sink ES 写入 ES(带密码)
限流的原理
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
STM32 - DMA
ABC D - Distinct Trio (Number of k-tuples
a different object with the same identifier value was already associated with the session
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
1. Get data - requests.get()
剑指offer基础版 ---- 第26天
MySQL transaction (transaction) (this is enough..)
面试官,不要再问我三次握手和四次挥手