当前位置:网站首页>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=''
)
边栏推荐
- What is cloud primordial? This time, I can finally understand!
- Leetcode 面试题 16.11. 跳水板
- iframe嵌套详解
- AI开发调试系列第二弹:多机分布式调测探索之旅
- 距离度量 —— 杰卡德距离(Jaccard Distance)
- Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;
- Wechat applet video sharing platform system graduation design completion (7) Interim inspection report
- A simple PHP personal card issuing program v4.0
- Wechat applet video sharing platform system graduation design completion (5) assignment
- 如何设置VSCode删除整行快捷键?
猜你喜欢

Pit encountered during installation of laravel frame

揭秘得物客服IM全链路通信过程

Leetcode 面试题 16.15. 珠玑妙算

What is cloud primordial? This time, I can finally understand!

Wechat applet video sharing platform system graduation design completion (4) opening report

Qt Official examples: Qt Quick Controls - Gallery

再放寬!這些應届生,可直接落戶上海

CDN acceleration and breaking J anti-theft chain function

Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum

Responses of different people in technology companies to bugs | daily anecdotes
随机推荐
阿里三面被面试官狂问Redis,简历上再也不敢写'精通'了
Leetcode 面试题 16.15. 珠玑妙算
Meal card hdu2546
The official docker image running container in version 1.5.1 can be set to use MySQL 8 driver?
深度神经网络总结
Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理
How to write controller layer code gracefully?
Leetcode 面试题 17.01. 不用加号的加法
options should NOT have additional properties
Wechat applet video sharing platform system graduation design completion (5) assignment
夜神模擬器+Fiddler抓包測試App
Redis (6) -- object and data structure
Wechat applet video sharing platform system graduation design completion (6) opening defense ppt
UE4 用spline画正圆
Detailed explanation of cjson usage
iframe嵌套详解
Relax again! These fresh students can settle directly in Shanghai
实施阴影介绍
Slam | how to align timestamps?
SAP S/4HANA OData Mock Service 介绍