当前位置:网站首页>第六章:决胜秋招
第六章:决胜秋招
2022-07-30 16:17:00 【长沙的沙】
Q1
create table employee(
employee_id char(4) not null,
employee_name varchar(100) not null,
salary integer not null,
department_id char(4) not null,
primary key(Employee_id)
);
insert into employee values('0001','Joe','70000','0001');
insert into employee values('0002','Henry','80000','0002');
insert into employee values('0003','Sam','60000','0002');
insert into employee values('0004','Max','50000','0001');
create table department(
department_id char(4) not null,
department_name varchar(100) not null,
primary key(department_id)
);
insert into department values('0001','IT');
insert into department values('0002','Sales');
select d.department_name,employee_name,max_salary
from employee
join department d on employee.department_id = d.department_id
join (select department_id,max(salary) as max_salary
from employee
group by department_id)temp
on temp.department_id = d.department_id
where employee.salary = max_salary
order by
max_salary desc;
Q2
create table seat(id int(11) not null,
student varchar(100) not null,
primary key(id));
-- 插入数据
insert into seat(id,student) values('1','ABBot');
insert into seat(id,student) values('2','Doris');
insert into seat(id,student) values('3','Emerson');
insert into seat(id,student) values('4','Green');
insert into seat(id,student) values('5','Jeames');
SELECT
(CASE
WHEN MOD(id, 2) != 0 AND counts != id THEN id + 1
WHEN MOD(id, 2) != 0 AND counts = id THEN id
ELSE id - 1
END) AS id,
student
FROM
seat,
(SELECT
COUNT(*) AS counts
FROM
seat) AS seat_counts
ORDER BY id ASC;
Q3
create table score(
id int not null,
score decimal(3,2) not null,
primary key(id)
);
-- 插入数据:
insert into score(id,score) values(1,3.50);
insert into score(id,score) values(2,3.65);
insert into score(id,score) values(3,4.00);
insert into score(id,score) values(4,3.85);
insert into score(id,score) values(5,4.00);
insert into score(id,score) values(6,3.65);
select score,
(select count(distinct score)
from score
where score>=s.score) as rank
from score as s
order by score desc;
Q4
-- 创建Logs表
create table Logs(id int not null,
num int not null,
primary key(id)
);
-- 插入数据
insert into Logs(id,num) values('1','1');
insert into Logs(id,num) values('2','1');
insert into Logs(id,num) values('3','1');
insert into Logs(id,num) values('4','2');
insert into Logs(id,num) values('5','1');
insert into Logs(id,num) values('6','2');
insert into Logs(id,num) values('7','2');
select distinct A.num ConsecutiveNums from logs as a
inner join logs as B on A.id+1 = B.id and A.num=B.num
inner join logs as C on B.id+1 = C.id and B.num=C.num;
Q5
-- 创建tree表
create table tree(id char(1),
p_id integer,
primary key(id));
-- 插入数据
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);
commit;
SELECT id,
CASE WHEN p_id IS NULL THEN 'Root'
WHEN id in (SELECT p_id FROM tree) THEN 'Inner'
ELSE 'Leaf' END
AS TYPE
FROM tree
ORDER BY id
Q6
create table employee (Id int primary key,
Name varchar(255),
Department varchar(255),
Managerid int);
-- 插入数据
insert into employee values('101','John','A','null');
insert into employee values('102','Dan','A','101');
insert into employee values('103','James','A','101');
insert into employee values('104','Amy','A','101');
insert into employee values('105','Anne','A','101');
insert into employee values('106','Ron','B','101');
select name
from (select ManagerId,count(ID) as n
from employee
group by ManagerId) m, employee e
where m.ManagerId = e.Id and n >=5;
Q7
create table employee (Id int primary key,
Name varchar(255),
Department varchar(255),
Managerid int);
-- 插入数据
insert into employee values('101','John','A','null');
insert into employee values('102','Dan','A','101');
insert into employee values('103','James','A','101');
insert into employee values('104','Amy','A','101');
insert into employee values('105','Anne','A','101');
insert into employee values('106','Ron','B','101');
select name
from (select ManagerId,count(ID) as n
from employee
group by ManagerId) m, employee e
where m.ManagerId = e.Id and n >=5;
边栏推荐
- 23. Please talk about the difference between IO synchronization, asynchronous, blocking and non-blocking
- (1) Cloud computing technology learning - virtualized vSphere learning
- Leetcode 119. 杨辉三角 II
- 【C语言】指针和数组的深入理解(第二期)
- How to implement timing tasks for distributed applications in Golang
- hcip--ospf综合实验
- [HMS core] [FAQ] Collection of typical problems of push kit, AR Engine, advertising service, scanning service 2
- Why is there no data reported when the application is connected to Huawei Analytics in the application debugging mode?
- 路遇又一个流量风口,民宿长期向好的逻辑选对了吗
- 游戏多开检测的几种实现方法及破解方法参考
猜你喜欢

Jetpack Compose 到底优秀在哪里?| 开发者说·DTalk

【HMS core】【Media】【Video Editing Service】 The online material cannot be displayed, it is always in the loading state or the network is abnormal

go 学习03 基础知识变量类型

影像信息提取DEM

Google engineer "code completion" tool; "Transformers NLP" accompanying book code; FastAPI development template; PyTorch model acceleration tool; cutting-edge papers | ShowMeAI News Daily

Pytorch 训练技巧

70 lines of code, a desktop automatic translation artifact

C#西门子S7 协议通过偏移量的方式读写PLC DB块

应用OPC解决方案实现控制系统数据的安全交换

Wuhan Star Sets Sail: Overseas warehouse infrastructure has become a major tool for cross-border e-commerce companies to go overseas
随机推荐
新人学习小熊派网络应用开发
武汉星起航:海外仓基础建设成为跨境电商企业的一大出海利器
UI测试新方法:视觉感知测试详解
【HMS core】【FAQ】push kit、分析服务、视频编辑服务典型问题合集3
围绕用户思维,木鸟与途家如何实现乡村民宿下的用户运营
PCIE下载的驱动安装
Horizontal Pod Autoscaler(HPA)
[TypeScript] Introduction, Development Environment Construction, Basic Types
登录模块调试-软件调试入门
LeetCode-283-移动零
Jetpack Compose 到底优秀在哪里?| 开发者说·DTalk
在 Chrome 浏览器中安装 JSON 显示插件
MySql 和 PostgreSQL 数据库 根据一张表update另一张表数据
node.js中怎么连接redis?
论文阅读 (63):Get To The Point: Summarization with Pointer-Generator Networks
JVM学习----垃圾回收
The service already exists!解决办法
加密生活,Web3 项目合伙人的一天
【开发者必看】【push kit】推送服务典型问题合集2
华为云数据治理生产线DataArts,让“数据‘慧’说话”