面试sql
创建表
create table Student
( Sno varchar(20) primary key,Sname varchar(20) UNIQUE,Ssex varchar(2),Sbirthday date,class varchar(20)
)create table Course
( Cno varchar(20) primary key,Cname varchar(20) UNIQUE,Tno varchar(20)
)create table Score
( Sno varchar(20),Cno varchar(20),Degree smallint,primary key(Sno,Cno),FOREIGN KEY (Cno) references Course(Cno),FOREIGN KEY (Sno) references Student(Sno)
)create table Teacher
( Tno varchar(20) primary key,Tname varchar(20) UNIQUE,Tsex varchar(20),Tbirthday date,Prof varchar(20),Depart varchar(20)
)
INSERT INTO Student (Sno,Sname,Ssex,Sbirthday,class)VALUES('108','曾华','男','1997/09/01','95033'),('105','匡明','男','1995/10/02','95031'),('107','王丽','女','1996/01/23','95033'),('101','李军','男','1996/02/20','95033'),('109','王芳','女','1995/02/10','95031'),('103','陆君','男','1994/06/03','95031'); INSERT INTO Course(Cno,Cname,Tno)VALUES('3-105','计算机导论','825'),('3-245','操作系统','804'),('6-166','数字电路','856'),('9-888','高等数学','831') ;INSERT INTO Score(Sno,Cno,Degree)VALUES('103','3-245',86),('105','3-245',75),('109','3-245',68),('103','3-105',92),('105','3-105',88),('109','3-105',76),('101','3-105',64),('107','3-105',91),('108','3-105',78),('101','6-166',85),('107','6-166',79),('108','6-166',81);INSERT INTO Teacher (Tno,Tname,Tsex,Tbirthday,prof,Depart)VALUES('804','李城','男','1980-12-02','副教授','计算机系'),('856','张旭','男','1977-03-12','讲师','电子工程系'),('825','王萍','女','1992-05-05','助教','计算机系'),('831','刘冰','女','1993-01-20','助教','电子工程系');
--1、 查询Student表中的所有记录的Sname、Ssex和Class列。
select Sname,Ssex,Class from Student
--2、 查询教师所有的单位即不重复的Depart列。
--3、 查询Student表的所有记录。
select * from Student
--4、 查询Score表中成绩在60到80之间的所有记录。
select * from Score where Degree between 60 and 80
--5、 查询Score表中成绩为85,86或88的记录。
select *from Score where Degree in(85,86,88)
--6、 查询Student表中“95031”班或性别为“女”的同学记录。
select * from Student where Class=95031 or Ssex='女'
--7、 以Class降序查询Student表的所有记录。
select * from Student order by Class DESC
--8、 以Cno升序、Degree降序查询Score表的所有记录。
select *from Score order by Cno,Degree DESC
--9、 查询“95031”班的学生人数。
select count(Class) from Student where Class=95031
--10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
select Sno,Cno
from Score
where Degree =(select max(degree) from score)
--11、 查询每门课的平均成绩。
select Cno,AVG(Degree)
from Score
where Cno='3-105' group by Cno
--12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select AVG(Degree)
from Score
where Cno=(
select Cno
from Score
group by Cno
having count(Cno)>=5
)
and Cno like '3%'
--13、查询分数大于70,小于90的Sno列。
SELECT sno from (
SELECT sno,MIN(degree) as min_score,MAX(degree) as max_score
from score
GROUP BY sno) a
where a.min_score>70
and a.max_score <90;
--14、查询所有学生的Sname、Cno和Degree列。
select Sname,S.Cno,S.Degree
from Student,Score S
where Student.Sno=S.Sno
--15、查询所有学生的Sno、Cname和Degree列。
select Sno,Cname,Degree
from Course,Score
where Course.Cno=Score.Cno
--16、查询所有学生的Sname、Cname和Degree列。
select Sname,Cname,Degree
from Student,Score,Course
where Student.Sno=Score.Sno
and Score.Cno=Course.Cno
--17、 查询“95033”班学生的平均分。
select AVG(Degree)
from Student,Score
where Student.Sno=Score.Sno
and Class='95033'
--18、 假设使用如下命令建立了一个grade表:
--现查询所有同学的Sno、Cno和rank列。
--19、 查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
SELECT a.* from student a
INNER JOIN score b
on a.sno=b.sno
where b.degree>(select degree from score xinner join course y on x.cno=y.cnowhere sno='109' and cname='3-105');
--20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
select *
from Score A
where Degree<(select MAX(Degree)
from Score B
where A.Cno=B.Cno)
and Sno in(select Sno
from Score group by Sno having count(*)>1
)
--21、 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
select *
from student,Score
where student.Sno=Score.Sno
and Score.Degree>(select Degree
from Score
where Cno='3-105' and Sno='109')
--22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
select Sno,Sname,Sbirthday
from student
where year(student.Sbirthday)=(select year(Sbirthday)
from student
where Sno='107')
--23、查询“张旭“教师任课的学生成绩。
select Degree
from Score,Teacher,Course
where Teacher.Tname='张旭'
and Teacher.Tno=Course.Tno
and Course.Cno=Score.Cno
select Sno,Cno,Degree
from Score
where Cno in (select Cno
from Course
where Tno in ( select Tno
from Teacher
where Tname='张旭'
)
)
--24、查询选修某课程的同学人数多于5人的教师姓名。
select Tname
from Teacher
where Tno in (select Tno
from Course
where Cno in (select Cno
from Score
group by Cno having COUNT(*)>5
)
)
--25、查询95033班和95031班全体学生的记录。
select *
from student
where Class='95033' or Class='95031'
--26、查询存在有85分以上成绩的课程Cno.
select distinct Cno from Score where Degree>85
--27、查询出“计算机系“教师所教课程的成绩表。
select Sno,Cno ,Degree
from Score
where Cno in (select Cno
from Course
where Tno in (select Tno
from Teacher
where Depart='计算机系'
)
)
--29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
select Cno,Sno,Degree
from Score A
where (select Degree
from Score B
where Cno='3-105' and B.Sno=A.Sno)>=(select Degree
from Score C
where Cno='3-245' and C.Sno=A.Sno)
order by Degree DESC
select *
from Score
where Cno='3-105' and Degree >any(select Degree
from Score
where Cno='3-245')
--30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.
select Cno,Sno,Degree
from Score A
where (select Degree
from Score B
where Cno='3-105' and B.Sno=A.Sno)>=(select Degree
from Score C
where Cno='3-245' and C.Sno=A.Sno
)
--31、 查询所有教师和同学的name、sex和birthday.
select distinct Sname as name,Ssex as sex,Sbirthday as birthday
from student
UNION
select distinct Tname as name,Tsex as sex,Tbirthday as birthday
from Teacher
--32、查询所有“女”教师和“女”同学的name、sex和birthday.
select distinct Sname as name,Ssex as sex,Sbirthday as birthday
from student
where Ssex='女'
UNION
select distinct Tname as name,Tsex as sex,Tbirthday as birthday
from Teacher
where Tsex='女'
--33、 查询成绩比该课程平均成绩低的同学的成绩表。
select Sno,Cno,Degree
from Score A
where A.Degree<(select AVG(Degree)
from Score B
where A.Cno=B.Cno)
--34、 查询所有任课教师的Tname和Depart.
select Tname,Depart
from Teacher
where Tname in (select distinct Tname
from Teacher,Course,Score
where Teacher.Tno=Course.Tno and Course.Cno=Score.Cno
)
select Tname,Depart
from Teacher
where tno in (select Tno from course
where Cno in (select distinct Cno
from Score
)
)
--35、 查询所有未讲课的教师的Tname和Depart.
select Tname,Depart
from Teacher
where Tname not in (select distinct Tname
from Teacher,Course,Score
where Teacher.Tno=Course.Tno and Course.Cno=Score.Cno
)
--36、查询至少有2名男生的班号。
select Class
from Student
where Ssex='男' group by Class having COUNT(*)>1
--37、查询Student表中不姓“王”的同学记录。
select *
from student
where Sname not like ('王%')
--38、查询Student表中每个学生的姓名和年龄。
select Sname,YEAR(GETDATE())-year(Sbirthday) from student
--39、查询Student表中最大和最小的Sbirthday日期值。
select MAX(Sbirthday) as 最大,MIN(Sbirthday) as 最小 from student
--40、以班号和年龄从大到小的顺序查询Student表中的全部记录。
select * from student order by Class desc,Sbirthday ASC
--42、查询最高分同学的Sno、Cno和Degree列。
select Tname,Cname
from Teacher,Course
where Tsex='男' and Teacher.Tno=Course.Tno
--43、查询和“李军”同性别的所有同学的Sname.
select Sname
from student
where Ssex=(select Ssex
from student
where Sname='李军') and Sname not in ('李军')
--44、查询和“李军”同性别并同班的同学Sname.
select Sname
from student
where Ssex=(select Ssex
from student
where Sname='李军')
and Sname not in ('李军')
and Class=(select Class
from student
where Sname='李军')
--45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
select Sno,Degree
from Score
where Sno in (select Sno
from student
where Ssex='男')
and Cno in (select Cno
from Course
where Cname='计算机导论'
)
相关文章:
面试sql
创建表 create table Student ( Sno varchar(20) primary key,Sname varchar(20) UNIQUE,Ssex varchar(2),Sbirthday date,class varchar(20) )create table Course ( Cno varchar(20) primary key,Cname varchar(20) UNIQUE,Tno varchar(20) )create table Score ( …...

Python编程自动化办公案例(2)
作者简介:一名在校计算机学生、每天分享Python的学习经验、和学习笔记。 座右铭:低头赶路,敬事如仪 个人主页:网络豆的主页 目录 前言 一.前期代码 二.实现批量读取 1.os库 2.实现思路 (1&#…...

Vulnhub 渗透练习(七)—— FRISTILEAKS: 1.3
环境搭建 下载链接 virtualbox 打开靶机设置为 host-only,攻击机同样。 具体可点此处 信息收集 开了个 80 端口。 用的是 apache 2.2.15 ,这个版本有个解析漏洞。 目录 根据首页的图片猜测 /fristi/ 目录(不过我没想到 -_-&#x…...

阶段二10_面向对象高级_分类分包思想和案例环境搭建
一.分类思想 1.分类思想概念: 分工协作,专人干专事 2.信息管理系统分类[案例] Student 类-------------------->标准学生类,封装键盘录入的学生信息(id , name , age , birthday) StudentDao 类-----------------&…...
关于打印工具print-js的使用
https://www.jianshu.com/p/f6f09dd9f7db第一步 安装组件//安装print-js npm install print-js --save //删除print-js npm uninstall print-js //安装固定版本 npm install print-js版本号 --save // 全局安装 npm install print-js --save -g第二步 引入组件安装成功后&#…...
Doxygen使用
文章目录简介Doxygen的安装Doxygen的配置生成配置文件常用配置Doxygen注释头文件注释:函数的注释:Doxygen文档生成reference简介 Doxygen 是一个流行的用于生产代码文档的工具,关于它的介绍可以参考官网:https://www.doxygen.nl/index.html。 我使用Dox…...
MySQL数据库调优————表结构设计优化
三范式 第一范式 字段具有原子性,即数据库表的每一个字段都是不可分割的原子数据项,不能是集合、数组、记录等非原子数据项当实体中的每个属性有多个值时,必须拆分为不同的属性 第二范式 满足第一范式的基础上,要求每一行数据…...
set对象和map对象
1 Set对象 介绍: Set数据结构类似数组,但所有成员的值唯一。 Set本身为一个构造函数,用来生成 Set数据结构,使用 add方法来添加新成员。 let a new Set(); [1,2,2,1,3,4,5,4,5].forEach(x>a.add(x)); for(let k of a){ console.log(k…...
stream()流的使用
文章目录引入流流的操作中间操作终端操作流的使用谓词筛选筛选各异的元素流的切片截断流跳过元素映射流的扁平化查找和匹配归约元素求和、最大值和最小值数值流构建流由值构建流由数组创建流引入流 java api提供的一种利用声明式的方式处理数据集合的一个东西,可以…...
C++学习笔记-常量
在程序执行过程中,其值不能改变的量称为常量(Constant)。普通常量的类型是根据数据的书写形式来决定的。如 100 是整型常量,0.5 是实型常量,‘q’ 是字符型常量,“qianfeng” 是字符串常量。 常量是固定值,在程序执行期…...

JavaScript系列之实现继承的几种方式
文章の目录一、借助父构造函数继承属性1、实现方式2、优点3、缺点二、原型链继承1、实现方式2、优点3、缺点三、组合继承四、ES6继承的实现方式参考写在最后一、借助父构造函数继承属性 1、实现方式 先定义一个父构造函数(this指向为window);再定义一个子构造函数…...
java面试准备
1.自我介绍: 2.基础 : 1.集合 : java容器中分为collection 和map两大类 collection 分为list集合(有序且重复的),set集合(无序,不可重复) list集合分为arrayList集合 : 查询快,增删慢,它是基于数组结构的,对数据的增删是在数组的尾部进行添加或删除的,其效率相对于LinkedList…...

kafka-6-python单线程操作kafka
使用Python操作Kafka:KafkaProducer、KafkaConsumer Python kafka-python API的帮助文档 1 kafka tools连接 (1)/usr/local/kafka_2.13-3.4.0/config/server.properties listeners PLAINTEXT://myubuntu:9092 advertised.listenersPLAINTEXT://192.168.1.8:2909…...

【Spring教程】1.Spring概述
1、概述 1.1、Spring是什么? Spring 是一款主流的 Java EE 轻量级开源框架 ,Spring 由“Spring 之父”Rod Johnson 提出并创立,其目的是用于简化 Java 企业级应用的开发难度和开发周期。Spring的用途不仅限于服务器端的开发。从简单性、可测…...

设计模式-代理模式
控制和管理访问 玩过扮白脸,扮黑脸的游戏吗?你是一个白脸,提供很好且很友善的服务,但是你不希望每个人都叫你做事,所以找了黑脸控制对你的访问。这就是代理要做的:控制和管理对象。 监视器编码 需求&…...
DPDK — MALLOC(librte_malloc,Memory Manager,内存管理组件)
目录 文章目录 目录MALLOC(librte_malloc,Memory Manager,内存管理组件)rte_malloc() 接口malloc_heap 结构体malloc_elem 结构体内存初始化流程内存申请流程内存释放流程MALLOC(librte_malloc,Memory Manager,内存管理组件) MALLOC 库基于 hugetlbfs 内核文件系统来实…...

【Java开发】Spring 12 :Spring IOC控制反转和依赖注入(解决单接口多实现类调用)
IOC 是 Inversion of Control 的简写,译为“控制反转”,Spring 通过 IOC 容器来管理所有 Java 对象的实例化和初始化,控制对象与对象之间的依赖关系。我们将由 IOC 容器管理的 Java 对象称为 Spring Bean,它与使用关键字 new 创建…...

【C++学习】基础语法(三)
众所周知C语言是面向过程的编程语言,关注的是过程;解决问题前,需要分析求解的步骤,然后编辑函数逐步解决问题。C是基于面向对象的,关注的是对象,将一件事拆分成不同的对象,不同对象间交互解决问…...

k8s自动化安装脚本(kubeadm-1.23.7)
文章目录介绍软件架构版本介绍更新内容2023-02-192023-02-152023-02-142023-02-102022-10-202022-08-06准备部署包操作步骤环境准备结构备注解压部署包修改host文件脚本使用方式初始化环境验证ansible配置安装k8s集群登录master的节点添加node节点master节点状态检查组件安装安…...

面试题记录
Set与Map的区别 map是键值对,set是值的集合。键,值可以是任何类型map可以通过get获取,map不能。都能通过迭代器进行for…of遍历set的值是唯一的,可以做数组去重,map,没有格式限制,可以存储数据…...
基于算法竞赛的c++编程(28)结构体的进阶应用
结构体的嵌套与复杂数据组织 在C中,结构体可以嵌套使用,形成更复杂的数据结构。例如,可以通过嵌套结构体描述多层级数据关系: struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...

地震勘探——干扰波识别、井中地震时距曲线特点
目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波:可以用来解决所提出的地质任务的波;干扰波:所有妨碍辨认、追踪有效波的其他波。 地震勘探中,有效波和干扰波是相对的。例如,在反射波…...

树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...
Leetcode 3576. Transform Array to All Equal Elements
Leetcode 3576. Transform Array to All Equal Elements 1. 解题思路2. 代码实现 题目链接:3576. Transform Array to All Equal Elements 1. 解题思路 这一题思路上就是分别考察一下是否能将其转化为全1或者全-1数组即可。 至于每一种情况是否可以达到…...
python如何将word的doc另存为docx
将 DOCX 文件另存为 DOCX 格式(Python 实现) 在 Python 中,你可以使用 python-docx 库来操作 Word 文档。不过需要注意的是,.doc 是旧的 Word 格式,而 .docx 是新的基于 XML 的格式。python-docx 只能处理 .docx 格式…...

令牌桶 滑动窗口->限流 分布式信号量->限并发的原理 lua脚本分析介绍
文章目录 前言限流限制并发的实际理解限流令牌桶代码实现结果分析令牌桶lua的模拟实现原理总结: 滑动窗口代码实现结果分析lua脚本原理解析 限并发分布式信号量代码实现结果分析lua脚本实现原理 双注解去实现限流 并发结果分析: 实际业务去理解体会统一注…...
【学习笔记】深入理解Java虚拟机学习笔记——第4章 虚拟机性能监控,故障处理工具
第2章 虚拟机性能监控,故障处理工具 4.1 概述 略 4.2 基础故障处理工具 4.2.1 jps:虚拟机进程状况工具 命令:jps [options] [hostid] 功能:本地虚拟机进程显示进程ID(与ps相同),可同时显示主类&#x…...

selenium学习实战【Python爬虫】
selenium学习实战【Python爬虫】 文章目录 selenium学习实战【Python爬虫】一、声明二、学习目标三、安装依赖3.1 安装selenium库3.2 安装浏览器驱动3.2.1 查看Edge版本3.2.2 驱动安装 四、代码讲解4.1 配置浏览器4.2 加载更多4.3 寻找内容4.4 完整代码 五、报告文件爬取5.1 提…...
Rapidio门铃消息FIFO溢出机制
关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系,以下是深入解析: 门铃FIFO溢出的本质 在RapidIO系统中,门铃消息FIFO是硬件控制器内部的缓冲区,用于临时存储接收到的门铃消息(Doorbell Message)。…...
ip子接口配置及删除
配置永久生效的子接口,2个IP 都可以登录你这一台服务器。重启不失效。 永久的 [应用] vi /etc/sysconfig/network-scripts/ifcfg-eth0修改文件内内容 TYPE"Ethernet" BOOTPROTO"none" NAME"eth0" DEVICE"eth0" ONBOOT&q…...