wonderful-sql 作业

Sql 作业

作业1:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vqZ3C6jP-1691141831237)(Sql 作业.assets/image-20230802160920037.png)]

答:

create table Employee
(Id integer not null,
Name varchar(32) ,
Salary integer,
departmentId integer,
primary key (Id)
);create table Department(
Id integer primary key,
Name varchar(30) not null
);insert into employee values (1,"Joe",70000,1);
insert into employee values (2,"Henry",80000,2);
insert into employee values (3,"Sam",60000,2);
insert into employee values (4,"Max",90000,1);
insert into department values(1,"IT");
insert into department values(2,"Sales");SELECT departmentId,  (SELECT Name FROM employeeWHERE departmentId = e.departmentId AND salary = MAX(e.salary)
) AS Employee,MAX(salary) AS max_salary
FROM employee e
GROUP BY departmentId

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7KndS7ds-1691141831238)(Sql 作业.assets/image-20230804092217531.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-17BJfyBJ-1691141831238)(Sql 作业.assets/image-20230804092225469.png)]

答:

create table seat(
id int primary key,
Name varchar(30) not null
);
insert into seat values(1,"Abbot");
insert into seat values(2,"Doris");
insert into seat values(3,"Emerson");
insert into seat values(4,"Green");
insert into seat values(5,"Jeames");
select * from seat;SELECT(CASE WHEN MOD(id,2)=1 AND id=(SELECT COUNT(id) FROM seat) THEN idWHEN MOD(id,2)=0 THEN id-1ELSE id+1END
) AS id,name
FROM seat
ORDER BY id;

解决相关方法:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yT05u3Wg-1691141831240)(Sql 作业.assets/image-20230804101845265.png)]

答:

create table score(
class int primary key,
score_avg int 
);
insert into score values(1,93);
insert into score values(2,93);
insert into score values(3,93);
insert into score values(4,91);
select class,score_avg,
rank() over (order by score_avg desc) as rank1,
dense_rank() over (order by score_avg desc) as rank2,
row_number() over(order by score_avg desc) as rank3
from score;

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SWrD1UBj-1691141831241)(Sql 作业.assets/image-20230804114101982.png)]

答:

create table number(
id int primary key,
Num int
);
insert into number values(1,1); 
insert into number values(2,1);
insert into number values(3,1);
insert into number values(4,2);
insert into number values(5,1);
insert into number values(6,2);
insert into number values(7,2);
select * from number;
select distinct num as ConsecutiveNums
from (select num,if(@prev_num = num,@count:=@count+1,@count:=1)as consecutive_count, @prev_num:=numfrom numbercross join(select @count:=0,@prev_num:=NULL) as varsorder by id
)as t
where consecutive_count>=3

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NLUtMolU-1691141831242)(Sql 作业.assets/image-20230804114118880.png)]
在这里插入图片描述

答:

create table tree(
id int primary key,
p_id int
);
insert into tree values(1,null);
insert into tree values(2,1);
insert into tree values(3,1);
insert into tree values(4,2);
insert into tree values(5,2);
select * from tree;
select id , casewhen p_id is null then "Root"when id in (select p_id from tree) then "Inner"else "Leaf"end as Typefrom tree;

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-W1YkJBYP-1691141831243)(Sql 作业.assets/image-20230804151012952.png)]

答:

create table Employee2(
Id int primary key,
name varchar(50),
Department varchar(50),
ManagerId int
);
insert into employee2 values(101,"John","A",null);
insert into employee2 values(102,"Dan","A",101);
insert into employee2 values(103,"James","A",101);
insert into employee2 values(104,"Amy","A",101);
insert into employee2 values(105,"Anne","A",101);
insert into employee2 values(106,"Ron","B",101);
select * from employee2;
select name
from (select ManagerId , count(ManagerId) as M_count
from employee2
group by ManagerId
) as ManagerCount , employee2
where ManagerCount.M_count = 5 and ManagerCount.ManagerId = employee2.Id

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UK1eXmVC-1691141831244)(Sql 作业.assets/image-20230804163219597.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ldo6XIsO-1691141831244)(Sql 作业.assets/image-20230804163229875.png)]

答:

drop table if exists survey_log;
create table survey_log(
uid int ,
action varchar(20) check(action = "show" or action="answer" or action = "skip"),
question_id int,
answer_id int,
q_num int,
timestamp timestamp
);
insert into survey_log values(5,"show",285,null,1,123);
insert into survey_log values(5,"answer",285,124124,1,124);
insert into survey_log values(5,"show",369,null,2,125);
insert into survey_log values(5,"skip",369,null,2,126);
select * from survey_log;
select * from survey_log 
where action = "show" or action = "answer";
select question_id, count(*) as show1 from  survey_log
where action = "show"
group by question_id;select count_answer.question_id,max(answer/show1)
from
(select question_id, count(*) as show1 from  survey_log
where action = "show"
group by question_id) as count_show,
(select question_id, count(*) as answer from  survey_log
where action = "answer"
group by question_id) as count_answer
where count_answer.question_id  = count_show.question_id
group by count_answer.question_id

在这里插入图片描述
答:

select * from employee;
select * from department;
insert into employee value(5,"Janet",69000,1);
insert into employee value(6,"Randy",85000,1);
select department.Name as department,rank_employee.name as Employee,Salary
from (select name,salary,departmentId,
row_number() over (partition by departmentId order by salary desc) as rank1
from employee) 
as rank_employee,departmentwhere rank1 <=3 and department.id = rank_employee.departmentId

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/23500.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux:在使用UEFI固件的计算机上内核是如何被启动的

前言 启动计算机通常不是一件难事&#xff1a;按下电源键&#xff0c;稍等片刻&#xff0c;你就能看到一个登录界面&#xff0c;再输入正确的密码&#xff0c;就可以开启一天的网上冲浪之旅了。 但偶尔这件事没那么顺利&#xff0c;有时候迎接你的不是熟悉的登录界面&#xf…

mysql8配置binlog日志skip-log-bin,开启、关闭binlog,清理binlog日志文件

1.概要说明 binlog 就是binary log&#xff0c;二进制日志文件&#xff0c;这个文件记录了MySQL所有的DML操作。通过binlog日志我们可以做数据恢复&#xff0c;增量备份&#xff0c;主主复制和主从复制等等。对于开发者可能对binlog并不怎么关注&#xff0c;但是对于运维或者架…

机器学习和深度学习简述

一、人工智能、机器学习、深度学习的关系 近些年人工智能、机器学习和深度学习的概念十分火热&#xff0c;但很多从业者却很难说清它们之间的关系&#xff0c;外行人更是雾里看花。概括来说&#xff0c;人工智能、机器学习和深度学习覆盖的技术范畴是逐层递减的&#xff0c;三…

Java Maven 构建项目里面有个聚合的概念

Java 项目里面有个聚合的概念&#xff0c;它没有.net里面解决方案(solution)的能力&#xff0c;可以统一的编译项目下的所有包&#xff0c;或设置统一的打包路径&#xff0c;使用maven编译后的产物也不会像.net那样编译到当前项目的bin文件夹下面&#xff0c;而是统一的生成到配…

无人驾驶实战-第五课(动态环境感知与3D检测算法)

激光雷达的分类&#xff1a; 机械式Lidar&#xff1a;TOF、N个独立激光单元、旋转产生360度视场 MEMS式Lidar&#xff1a;不旋转 激光雷达的输出是点云&#xff0c;点云数据特点&#xff1a; 简单&#xff1a;x y z i &#xff08;i为信号强度&#xff09; 稀疏&#xff1a;7%&…

WPF中自定义Loading图

纯前端方式&#xff0c;通过动画实现Loading样式&#xff0c;如图所示 <Grid Width"35" Height"35" HorizontalAlignment"Center" VerticalAlignment"Center" Name"Loading"><Grid.Resources><DrawingBrus…

【云原生】k8s组件架构介绍与K8s最新版部署

个人主页&#xff1a;征服bug-CSDN博客 kubernetes专栏&#xff1a;kubernetes_征服bug的博客-CSDN博客 目录 1 集群组件 1.1 控制平面组件&#xff08;Control Plane Components&#xff09; 1.2 Node 组件 1.3 插件 (Addons) 2 集群架构详细 3 集群搭建[重点] 3.1 mi…

从价值的角度看,为何 POSE 通证值得长期看好

PoseSwap 是 Nautilus Chain 上的首个 DEX&#xff0c;基于 Nautilus Chain 也让其成为了首个以模块化构建的 Layer3 架构的 DEX。该 DEX 本身能够以 Dapp 层&#xff08;Rollup&#xff09;的形态&#xff0c;与其他应用层并行化运行。

Linux之 Ubuntu 安装常见服务 (二) Tomcat

安装TomCat 服务 1、安装JDK环境 https://www.oracle.com/java/technologies/downloads/ 下载的官网 wget https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.deb (sha256) 使用dpkg进行软件安装时&#xff0c;提示&#xff1a;dpkg&#xff1a;处理软件包XX…

Redis 总结【6.0版本的】

如果源码不编译&#xff0c;是无法实现自动跳转的&#xff0c; Redis在win上编译有点麻烦&#xff0c;我是使用的CentOS环境&#xff0c;Clion编译 编译完就可以直接通过shell连接Redis server了 server.c 中放的是就是主类 &#xff1a;6000多行左右是入口main()函数位置 Red…

三个主流数据库(Oracle、MySQL和SQL Server)的“单表造数

oracle 1.创建表 CREATE TABLE "YZH2_ORACLE" ("VARCHAR2_COLUMN" VARCHAR2(20) NOT NULL ENABLE,"NUMBER_COLUMN" NUMBER,"DATE_COLUMN" DATE,"CLOB_COLUMN" CLOB,"BLOB_COLUMN" BLOB,"BINARY_DOUBLE_COLU…

【Docker】Docker容器数据卷、容器卷之间的继承和DockerFIle的详细讲解

&#x1f680;欢迎来到本文&#x1f680; &#x1f349;个人简介&#xff1a;陈童学哦&#xff0c;目前学习C/C、算法、Python、Java等方向&#xff0c;一个正在慢慢前行的普通人。 &#x1f3c0;系列专栏&#xff1a;陈童学的日记 &#x1f4a1;其他专栏&#xff1a;CSTL&…

SpringBoot+vue 大文件分片下载

学习链接 SpringBootvue文件上传&下载&预览&大文件分片上传&文件上传进度 VueSpringBoot实现文件的分片下载 video标签学习 & xgplayer视频播放器分段播放mp4&#xff08;Range请求交互过程可以参考这个里面的截图&#xff09; 代码 FileController …

Python爬虫——爬虫时如何知道是否代理ip伪装成功?

前言 在进行爬虫时&#xff0c;我们可能需要使用代理IP来伪装自己的身份&#xff0c;以避免被网站封禁。如何判断代理IP是否伪装成功呢&#xff1f;本篇文章将围绕这个问题展开讲解&#xff0c;同时提供Python代码示例。 1. 确认代理IP地址 首先&#xff0c;我们需要确认代理…

Leetcode-每日一题【剑指 Offer 04. 二维数组中的查找】

题目 在一个 n * m 的二维数组中&#xff0c;每一行都按照从左到右 非递减 的顺序排序&#xff0c;每一列都按照从上到下 非递减 的顺序排序。请完成一个高效的函数&#xff0c;输入这样的一个二维数组和一个整数&#xff0c;判断数组中是否含有该整数。 示例: 现有矩阵 matri…

JMeter(二十四)、使用吞吐量控制器实现不同的用户操纵不同的业务

一、需求 需求&#xff1a;博客系统&#xff0c;模拟用户真实行为&#xff0c;80%的用户阅读文章&#xff0c;20%的用户创建文章&#xff0c;创建文章的用户随机的删除或者修改文章。 二、脚本实现 80%的用户查看文章 20%用户创建文章 根据post_id是否能整除2&#xff0c;决…

【Java】如何判断线程池任务执行完?

文章目录 前言1.需求分析2.实现概述3.具体实现3.1 统计完成任务数3.2 FutureTask3.3 CountDownLatch和CyclicBarrier 小结 前言 论是在项目开发中&#xff0c;还是在面试中过程中&#xff0c;总会被问到或使用到并发编程来完成项目中的某个功能。 例如某个复杂的查询&#xf…

嵌入式开发学习(STC51-12-I2C/IIC)

内容 在数码管右3位显示数字&#xff0c;从0开始&#xff0c;按K1键将数据写入到EEPROM内保存&#xff0c;按K2键读取EEPROM内保存的数据&#xff0c;按K3键显示数据加1&#xff0c;按K4键显示数据清零&#xff0c;最大能写入的数据是255&#xff1b; I2C介绍 I2C简介 I2C&…

第一百二十二天学习记录:C++提高:STL-vector容器(上)(黑马教学视频)

vector基本概念 功能&#xff1a; vector数据结构和数组非常相似&#xff0c;也称为单端数组 vector与普通数组区别&#xff1a; 不同之处在于数组是静态空间&#xff0c;而vector可以动态扩展 动态扩展&#xff1a; 并不是在原空间之后续接新的空间&#xff0c;而是找更大的内…

中国政府版 Windows 10 开发完成,即将大规模推广

早在今年 3 月 20 日&#xff0c;就有媒体曝光中国政府专用 Windows 10 已经完成第一版。而就在今天微软在上海举办的发布会中&#xff0c;微软再次透露了中国政府版 Windows 10 的最新情况——已经开始试点测试。这就意味着政府版 Windows 10 或很快大规模推广。 据了解&#…