面试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,没有格式限制,可以存储数据…...
【网络】每天掌握一个Linux命令 - iftop
在Linux系统中,iftop是网络管理的得力助手,能实时监控网络流量、连接情况等,帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...
线程同步:确保多线程程序的安全与高效!
全文目录: 开篇语前序前言第一部分:线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分:synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分ÿ…...

376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...

Python实现prophet 理论及参数优化
文章目录 Prophet理论及模型参数介绍Python代码完整实现prophet 添加外部数据进行模型优化 之前初步学习prophet的时候,写过一篇简单实现,后期随着对该模型的深入研究,本次记录涉及到prophet 的公式以及参数调优,从公式可以更直观…...

WordPress插件:AI多语言写作与智能配图、免费AI模型、SEO文章生成
厌倦手动写WordPress文章?AI自动生成,效率提升10倍! 支持多语言、自动配图、定时发布,让内容创作更轻松! AI内容生成 → 不想每天写文章?AI一键生成高质量内容!多语言支持 → 跨境电商必备&am…...
【学习笔记】深入理解Java虚拟机学习笔记——第4章 虚拟机性能监控,故障处理工具
第2章 虚拟机性能监控,故障处理工具 4.1 概述 略 4.2 基础故障处理工具 4.2.1 jps:虚拟机进程状况工具 命令:jps [options] [hostid] 功能:本地虚拟机进程显示进程ID(与ps相同),可同时显示主类&#x…...

Python Ovito统计金刚石结构数量
大家好,我是小马老师。 本文介绍python ovito方法统计金刚石结构的方法。 Ovito Identify diamond structure命令可以识别和统计金刚石结构,但是无法直接输出结构的变化情况。 本文使用python调用ovito包的方法,可以持续统计各步的金刚石结构,具体代码如下: from ovito…...

华为OD机考-机房布局
import java.util.*;public class DemoTest5 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseSystem.out.println(solve(in.nextLine()));}}priv…...

如何应对敏捷转型中的团队阻力
应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中,明确沟通敏捷转型目的尤为关键,团队成员只有清晰理解转型背后的原因和利益,才能降低对变化的…...
Linux安全加固:从攻防视角构建系统免疫
Linux安全加固:从攻防视角构建系统免疫 构建坚不可摧的数字堡垒 引言:攻防对抗的新纪元 在日益复杂的网络威胁环境中,Linux系统安全已从被动防御转向主动免疫。2023年全球网络安全报告显示,高级持续性威胁(APT)攻击同比增长65%,平均入侵停留时间缩短至48小时。本章将从…...