当前位置:网站首页>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=''
)
边栏推荐
- [Oracle final review] addition, deletion and modification of tablespaces, tables, constraints, indexes and views
- 揭秘得物客服IM全链路通信过程
- Qt官方示例:Qt Quick Controls - Gallery
- Which securities company has a low, safe and reliable online account opening commission
- Leetcode 面试题 16.17. 连续数列
- Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;
- Wechat applet video sharing platform system graduation design completion (5) assignment
- 谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
- Unity learning shader notes [81] simple color adjustment post-processing (brightness, saturation, contrast)
- Leetcode 面试题 16.11. 跳水板
猜你喜欢
A simple PHP personal card issuing program v4.0
Ali was wildly asked by the interviewer on three sides. Redis dared not write 'proficient' on his resume anymore
Qt官方示例:Qt Quick Controls - Gallery
再放宽!这些应届生,可直接落户上海
UE4 用spline画正圆
LightGroupButton* sender = static_cast<LightGroupButton*>(QObject::sender());
CDN acceleration and breaking J anti-theft chain function
彻底搞懂基于Open3D的点云处理教程!
Leetcode 面试题 17.04. 消失的数字
鸿蒙第四次学习
随机推荐
CDN acceleration and breaking J anti-theft chain function
How to write controller layer code gracefully?
sql训练2
The difference between promise and observable
Leetcode 面试题 16.15. 珠玑妙算
Leetcode 面试题 16.11. 跳水板
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
What is cloud primordial? This time, I can finally understand!
PR曲线和ROC曲线概念及其区别
Leetcode 面试题 16.17. 连续数列
A good programmer is worth five ordinary programmers!
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
1.5.1版本官方docker镜像运行容器,能设置使用 mysql 8驱动吗?
C语言中函数参数传递的三种方式
Leetcode interview question 16.15 Abacus wonderful calculation
呆错图床系统源码图片CDN加速与破J防盗链功能
Implementation shadow introduction
Troubleshooting ideas that can solve 80% of faults
Uncover the whole link communication process of dewu customer service im
距离度量 —— 杰卡德距离(Jaccard Distance)