当前位置:网站首页>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=''
)
边栏推荐
- Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
- Basic idea of quick sorting (easy to understand + examples) "suggestions collection"
- Leetcode(81)——搜索旋转排序数组 II
- Eliminate the yellow alarm light on IBM p750 small computer [easy to understand]
- [Northwestern Polytechnic University] information sharing of the first and second postgraduate examinations
- 彻底搞懂基于Open3D的点云处理教程!
- Which securities company has a low, safe and reliable online account opening commission
- iptable端口重定向 MASQUERADE[通俗易懂]
- 开源物联网平台ThingsBoard的安装
- Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum
猜你喜欢

深度学习数学基础

昨天阿里学长写了一个责任链模式,竟然出现了无数个bug

Web版3D可视化工具,程序员应该知道的97件事,AI前沿论文 | 资讯日报 #2022.07.01

After 22 years in office, the father of PowerShell will leave Microsoft: he was demoted by Microsoft for developing PowerShell

夜神模擬器+Fiddler抓包測試App

Night God simulator +fiddler packet capture test app

A simple PHP personal card issuing program v4.0

M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )

Qt Official examples: Qt Quick Controls - Gallery

彻底搞懂基于Open3D的点云处理教程!
随机推荐
How to write controller layer code gracefully?
夜神模擬器+Fiddler抓包測試App
服务器php环境搭建教程,PHP服务端环境搭建图文详解
UE4 用spline畫正圓
How to set vscode to delete the whole line shortcut key?
Introduction to sap s/4hana OData mock service
文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
RTE11- 中断解耦功能
QQmlApplicationEngine
科技公司不同人对Bug的反应 | 每日趣闻
Night God simulator +fiddler packet capture test app
揭秘得物客服IM全链路通信过程
Leetcode(81)——搜索旋转排序数组 II
Redis (7) -- database and expiration key
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
options should NOT have additional properties
Web版3D可视化工具,程序员应该知道的97件事,AI前沿论文 | 资讯日报 #2022.07.01
C语言中函数参数传递的三种方式
paddlepaddle 28 搭建基于卷积的自动编码机
QQmlApplicationEngine