当前位置:网站首页>SQL training 2
SQL training 2
2022-07-02 18:44:00 【Why not sell egg cakes well】
12 Information about the highest salary of current employees in all departments
, give dept_no/emp_no And corresponding salary
select d.dept_no,d.emp_no,max(salary)
from dept_emp d
inner join salaries s
on d.emp_no=s.emp_no
where d.to_date=s.to_date
group by d.dept_no
13 title The table is obtained according to title Grouping
The number of each group is greater than or equal to 2, give titile And the corresponding number
select title,count(*) t
from titles
group by title
having count(*) >=2;
15 lookup employees Table all emp_no It's odd
And last_name Not for mary Employee information , according to hire_date The reverse
select *
from employees e
where e.emp_no%2=1
//where e.emp_no mod 2 =1
and e.last_name is not 'mary'
//and e.last_name <> 'mary'
order by e.hire_date desc
16 Count the current title type
The current average salary of the corresponding employee ; The results show that title And the average wage avg
select t.title,avg(s.salary) avg
from titles t
inner join salaries s
on t.emp_no=s.emp_no
where t.to_date='9999-01-01'
and s.to_date='9999_01_01'
group by t.title;
17 Get the second highest salary at present
Of our employees dept_no And employee salary
select emp_no,salary
from salaries
where to_date='9999-01-01'
and salary=(
select distinct salary
from salaries
order by salary desc
limit 1,1
);
18 The number of the employee with the second highest salary
emp_no, salary salary,last_name as well as first_name, Do not use order by
select e.emp_no,max(s.salary),e.last_name,e.first_name
from employees e
inner join salaries s
on e.emp_no =s.emp_no
where s.to-date='lll'
and s.salary not in(
select max(salary)
from salaries
where to_date='jjj'
);
19 All employees last_name/first_name/dept_name
Including employees who have not been assigned departments for the time being ( Less departments , The employee is on the left )
incomprehension , What does three tables mean ;
select e.last_name.e.first_name,d.dept_name
from employees
left join dept_emp de on e.dept_no=de.dept_no
left join departments d on d.dept_no=de.dept_no;
20 Find the employee number emp_no=100001 The salary increase value of employees since their entry growth
select
(
(select salary from salaries where emp_no=10001 order by salary)
-(select salary from salaries where emp_no=10001 order by salary)
) growth;
21 Find out the salary increase of all employees since their entry
select emp_no, (s1.salary-s2.salary) as growth
from employees e
inner join salaries s1
on e.emp_no =s1.emp_no and s1.to_date='9999-01-01'
inner join salaries s2
on e.emp_no=s2.emp_no and e.hire_date=s2.from_date
order by growth asc;
22 The total number of employee increases corresponding to each department
dept_no dept_name frequency sum
select d.dept_no,d.dept_name,count(s.salary) 'sum'
from departments d
inner join dept_emp de on d.dept_no=de.dept_no
inner join salaries s on de.emp_no=s.emp_no
group by d.dept_no;
23 The current salary of all employees shall be in accordance with salary Sort
select emp_no,salary,count(distinct s2.salary) rank
from salaries s1,salaries s2
where s1.salary<=s2.salary
and s1.to_date='9999-01-01'
and s2.to_date='9999-01-01'
group by s1.emp_no
order by s1.salary desc , s1.emp_no asc
24 All non manager Current salary of employees
Ideas 1 Inquire about all employees
2 Filter out manager staff
select de.depts_no,e.emp_no,s.salary
from employees e
inner join salaries s
on e.emp_no=s.emp_no
and s.to_date=''
inner join dept_emp de
on e.emp_no=de.emp_no
where de.emp_no not in(
select emp_no
from dept_manager dm
where dm.to_date=''
)
边栏推荐
- How to use PS to extract image color and analyze color matching
- options should NOT have additional properties
- Esp32-c3 introductory tutorial question ⑪ - ESP tls: create_ ssl_ handle failed, tls_ io_ instance->options. trusted_ certs null
- SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
- exness深度好文:动性系列-黄金流动性实例分析(五)
- Leetcode interview question 16.15 Abacus wonderful calculation
- 【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介
- Wechat applet video sharing platform system graduation design completion (4) opening report
- 300+篇文献!一文详解基于Transformer的多模态学习最新进展
- “栈”的典型应用—表达式求值(C语言实现)
猜你喜欢

一款简约PHP个人发卡程序V4.0版本

彻底搞懂基于Open3D的点云处理教程!

Redis (6) -- object and data structure

工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座

UML 类图

如何清理废弃pv和其对应的文件夹

Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline

Wechat applet video sharing platform system graduation design completion (4) opening report
![Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理](/img/db/d745a434e76511742d1264706b5d9a.png)
Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理

QT official example: QT quick controls - Gallery
随机推荐
初夏,开源魔改一个带击杀音效的电蚊拍!
iptable端口重定向 MASQUERADE[通俗易懂]
快速排序基本思路(通俗易懂+例子)「建议收藏」
Meta universe chain game system development (logic development) - chain game system development (detailed analysis)
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
Web版3D可视化工具,程序员应该知道的97件事,AI前沿论文 | 资讯日报 #2022.07.01
【Oracle 期末复习】表空间、表、约束、索引、视图的增删改
深度神经网络总结
鸿蒙第四次学习
Chain game system development (unity3d chain game development details) - chain game development mature technology source code
How to use PS to extract image color and analyze color matching
Implementation shadow introduction
SLAM|如何时间戳对齐?
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
Deep neural network Summary
昨天阿里学长写了一个责任链模式,竟然出现了无数个bug
Uncover the whole link communication process of dewu customer service im
Chrome 正式支持 MathML,默认在 Chromium Dev 105 中启用
Ali was wildly asked by the interviewer on three sides. Redis dared not write 'proficient' on his resume anymore
AI开发调试系列第二弹:多机分布式调测探索之旅