当前位置:网站首页>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=''
)
边栏推荐
猜你喜欢
LightGroupButton* sender = static_cast<LightGroupButton*>(QObject::sender());
Qt官方示例:Qt Quick Controls - Gallery
CDN acceleration and breaking J anti-theft chain function
文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
什么是云原生?这回终于能搞明白了!
呆错图床系统源码图片CDN加速与破J防盗链功能
Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
Pit encountered during installation of laravel frame
Troubleshooting ideas that can solve 80% of faults
科技公司不同人对Bug的反应 | 每日趣闻
随机推荐
【Oracle 期末复习】表空间、表、约束、索引、视图的增删改
Unity learning shader notes [81] simple color adjustment post-processing (brightness, saturation, contrast)
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
Please, stop painting star! This has nothing to do with patriotism!
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
如何设置VSCode删除整行快捷键?
Wechat applet video sharing platform system graduation design completion (5) assignment
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
鸿蒙第四次学习
cJSON 使用详解
Night God simulator +fiddler packet capture test app
Chrome 正式支持 MathML,默认在 Chromium Dev 105 中启用
Redis(6)----对象与数据结构
RTE11- 中断解耦功能
文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
元宇宙链游系统开发(逻辑开发)丨链游系统开发(详细分析)
故障排查:kubectl报错ValidationError: unknown field \u00a0
C语言中函数参数传递的三种方式
Detailed explanation of cjson usage
Iframe nesting details