当前位置:网站首页>sql训练2
sql训练2
2022-07-02 17:05:00 【为什么不好好卖蛋饼】
12 所有部门中当前员工薪水最高的相关信息
,给出dept_no/emp_no以及对应的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表获取按照title进行分组
每组个数大于等于2,给出titile以及对应的数目
select title,count(*) t
from titles
group by title
having count(*) >=2;
15 查找employees表所有emp_no为奇数
且last_name不为mary的员工信息,按照hire_date逆序
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 统计当前各个title类型
对应的员工当前薪水平均工资;结果给出title以及平均工资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 获取当前薪水第二多
的员工的dept_no以及员工薪水
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 当前薪水排名第二的员工编号
emp_no,薪水salary,last_name以及first_name,不准使用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 所有员工的last_name/first_name/dept_name
包括暂时没有分配部门的员工(部门可以少,员工在左边)
不理解,三张表什么意思;
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 查找员工编号emp_no=100001员工入职以来薪水涨幅值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 查找所有员工自入职以来薪水涨幅情况
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 各个部门对应的员工涨幅的次数总和
dept_no dept_name 次数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 对所有员工当前薪水按照salary进行排序
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 所有非manager员工当前薪水情况
思路 1 查询所有员工情况
2 筛选掉manager员工
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=''
)
边栏推荐
- 【西北工业大学】考研初试复试资料分享
- SAP S/4HANA OData Mock Service 介绍
- Unity学习shader笔记[八十一]简单的颜色调整后处理(亮度,饱和度,对比度)
- Wechat applet video sharing platform system graduation design (3) background function
- 链游系统开发(Unity3D链游开发详情)丨链游开发成熟技术源码
- 夜神模擬器+Fiddler抓包測試App
- Unity learning shader notes [81] simple color adjustment post-processing (brightness, saturation, contrast)
- 微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
- 微信核酸检测预约小程序系统毕业设计毕设(2)小程序功能
- Please, stop painting star! This has nothing to do with patriotism!
猜你喜欢
拿起相机,便是最好的艺术疗愈
pycharm 修改 pep8 E501 line too long > 0 characters
微信核酸检测预约小程序系统毕业设计毕设(2)小程序功能
Unity学习shader笔记[八十二]增强单通道颜色渲染的黑白处理
Implementation shadow introduction
NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
夜神模拟器+Fiddler抓包测试App
Wechat applet video sharing platform system graduation design completion (5) assignment
能解决80%故障的排查思路
Uncover the whole link communication process of dewu customer service im
随机推荐
Relax again! These fresh students can settle directly in Shanghai
Leetcode interview question 17.04 Vanishing numbers
Architecture design - ID generator "suggestions collection"
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
Installation tutorial and simple call of Matplotlib
Leetcode 面试题 16.17. 连续数列
PR曲线和ROC曲线概念及其区别
微信核酸检测预约小程序系统毕业设计毕设(1)开发概要
Wechat applet video sharing platform system graduation design completion (4) opening report
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
exness深度好文:动性系列-黄金流动性实例分析(五)
链游系统开发(Unity3D链游开发详情)丨链游开发成熟技术源码
微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT
paddlepaddle 28 搭建基于卷积的自动编码机
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
【Oracle 期末复习】表空间、表、约束、索引、视图的增删改
Aptos tutorial - participate in the official incentive testing network (ait2 incentive testing network)
cJSON 使用详解
Tower safety monitoring system unattended inclination vibration monitoring system