面试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,没有格式限制,可以存储数据…...
循环冗余码校验CRC码 算法步骤+详细实例计算
通信过程:(白话解释) 我们将原始待发送的消息称为 M M M,依据发送接收消息双方约定的生成多项式 G ( x ) G(x) G(x)(意思就是 G ( x ) G(x) G(x) 是已知的)࿰…...
python/java环境配置
环境变量放一起 python: 1.首先下载Python Python下载地址:Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个,然后自定义,全选 可以把前4个选上 3.环境配置 1)搜高级系统设置 2…...
汽车生产虚拟实训中的技能提升与生产优化
在制造业蓬勃发展的大背景下,虚拟教学实训宛如一颗璀璨的新星,正发挥着不可或缺且日益凸显的关键作用,源源不断地为企业的稳健前行与创新发展注入磅礴强大的动力。就以汽车制造企业这一极具代表性的行业主体为例,汽车生产线上各类…...
HTML 列表、表格、表单
1 列表标签 作用:布局内容排列整齐的区域 列表分类:无序列表、有序列表、定义列表。 例如: 1.1 无序列表 标签:ul 嵌套 li,ul是无序列表,li是列表条目。 注意事项: ul 标签里面只能包裹 li…...
渲染学进阶内容——模型
最近在写模组的时候发现渲染器里面离不开模型的定义,在渲染的第二篇文章中简单的讲解了一下关于模型部分的内容,其实不管是方块还是方块实体,都离不开模型的内容 🧱 一、CubeListBuilder 功能解析 CubeListBuilder 是 Minecraft Java 版模型系统的核心构建器,用于动态创…...
页面渲染流程与性能优化
页面渲染流程与性能优化详解(完整版) 一、现代浏览器渲染流程(详细说明) 1. 构建DOM树 浏览器接收到HTML文档后,会逐步解析并构建DOM(Document Object Model)树。具体过程如下: (…...
Python 包管理器 uv 介绍
Python 包管理器 uv 全面介绍 uv 是由 Astral(热门工具 Ruff 的开发者)推出的下一代高性能 Python 包管理器和构建工具,用 Rust 编写。它旨在解决传统工具(如 pip、virtualenv、pip-tools)的性能瓶颈,同时…...
C#中的CLR属性、依赖属性与附加属性
CLR属性的主要特征 封装性: 隐藏字段的实现细节 提供对字段的受控访问 访问控制: 可单独设置get/set访问器的可见性 可创建只读或只写属性 计算属性: 可以在getter中执行计算逻辑 不需要直接对应一个字段 验证逻辑: 可以…...
提升移动端网页调试效率:WebDebugX 与常见工具组合实践
在日常移动端开发中,网页调试始终是一个高频但又极具挑战的环节。尤其在面对 iOS 与 Android 的混合技术栈、各种设备差异化行为时,开发者迫切需要一套高效、可靠且跨平台的调试方案。过去,我们或多或少使用过 Chrome DevTools、Remote Debug…...
Linux中《基础IO》详细介绍
目录 理解"文件"狭义理解广义理解文件操作的归类认知系统角度文件类别 回顾C文件接口打开文件写文件读文件稍作修改,实现简单cat命令 输出信息到显示器,你有哪些方法stdin & stdout & stderr打开文件的方式 系统⽂件I/O⼀种传递标志位…...
