当前位置:网站首页>【作业】2022.5.25 MySQL 查操作2
【作业】2022.5.25 MySQL 查操作2
2022-06-30 03:27:00 【Sprite.Nym】
-- 查询月薪最高的员工姓名和月薪
select ename as 员工姓名,
max(sal) as 最高月薪
from tb_emp;
-- 查询员工的姓名和年薪(年薪=(sal+comm)*13)
select ename as 员工姓名,
(sal + ifnull(comm, 0)) * 13
from tb_emp;
-- 查询有员工的部门的编号和人数
select dno as 部门编号,
count(*) as 人数
from tb_emp natural join tb_dept
group by dno;
-- 查询所有部门的名称和人数
select tb_dept.dno as 部门编号,
count(eno) as 人数
from tb_emp right join tb_dept
on tb_emp.dno = tb_dept.dno
group by tb_dept.dno;
-- 查询月薪超过平均月薪的员工的姓名和月薪
select ename as 员工姓名,
sal as 月薪
from tb_emp
where sal >= (select avg(sal) as 平均月薪 from tb_emp)
order by sal;
-- 查询月薪超过其所在部门平均月薪的员工的姓名、部门编号和月薪
select ename as 员工姓名,
dno as 部门编号,
sal as 月薪
from tb_emp t1 natural join ( select dno,
avg(sal) as 平均月薪
from tb_emp
group by dno) t2
where sal >= 平均月薪
order by dno, sal;
-- 查询部门中月薪最高的人姓名、月薪和所在部门名称
select ename,
max(sal),
dname
from tb_emp natural join tb_dept
group by tb_dept.dno;
-- 查询主管的姓名和职位
select ename,
job
from tb_emp
where eno in (select mgr
from tb_emp);
-- 查询月薪排名4~6名的员工排名、姓名和月薪
select 排名,
ename as 姓名,
sal as 月薪
from (select rank() over (order by sal desc) as '排名',
ename,
sal
from tb_emp) t2
where 排名 <= 6
and 排名 >= 4;
-- 查询每个部门月薪排前2名的员工姓名、月薪和部门编号
select ename as 员工姓名,
sal as 月薪,
dno as 部门编号
from (select ename,
sal,
dno,
rank() over (partition by dno order by sal desc) as 'rank_num'
from tb_emp) t2
where rank_num <= 2;
边栏推荐
- Number of students from junior college to Senior College (4)
- 51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation
- X书6.97版本shield-unidbg调用方式
- [ten minutes] manim installation 2022
- golang bilibili直播彈幕姬
- 广播模块代码在autojs4.1.1版本运行正常,但在pro7.0版本上运行报错(未解决)
- On the optimization and use of idea
- WPF Initialized事件在.cs中绑定不被触发的原因
- C [advanced part] C generic [need to be further supplemented: generic interfaces and instances of generic events]
- Principle of device driver
猜你喜欢

图的邻接矩阵存储 C语言实现BFS

Redis在windows系统中使用

Linked list: insert a node in the head

Compile a DLL without import table

【笔记】2022.6.7 数据分析概论

SDS understanding in redis

Litjson parses the generated JSON file and reads the dictionary in the JSON file

How to realize remote collaborative office, keep this strategy!

golang bilibili直播彈幕姬

X书6.97版本shield-unidbg调用方式
随机推荐
From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
Use common fileUpload to upload files
F1C100S自制开发板调试过程
Personal PC installation software
Ubuntu20.04 PostgreSQL 14 installation configuration record
Some common functions and precautions
Usage record of unity input system (instance version)
[practical skills] how to write agile development documents
C [advanced part] C generic [need to be further supplemented: generic interfaces and instances of generic events]
Hudi record
JS cross reference
Global and Chinese market of bronze valves 2022-2028: Research Report on technology, participants, trends, market size and share
Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
Compile a DLL without import table
Litjson parses the generated JSON file and reads the dictionary in the JSON file
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
1152_ Makefile learning_ Pattern matching rules
Tidb 6.0: making Tso more efficient tidb Book rush
Realization of BFS in C language by storing adjacency matrix of graph
Openssl3.0 learning 22 provider decoder