当前位置:网站首页>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=''
)
边栏推荐
- NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
- MySQL 关于 only_full_group_by 限制
- 微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告
- Use dosbox to run the assembly super detailed step "suggestions collection"
- Wechat nucleic acid detection appointment applet system graduation design (2) applet function
- Export Excel files using npoi
- pycharm 修改 pep8 E501 line too long > 0 characters
- 饭卡 HDU2546
- 服务器php环境搭建教程,PHP服务端环境搭建图文详解
- Wechat applet video sharing platform system graduation design completion (5) assignment
猜你喜欢
In early summer, Kaiyuan magic changed an electric mosquito racket with killing sound effect!
Wechat nucleic acid detection appointment applet system graduation design completion (4) opening report
工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座
Picking up the camera is the best artistic healing
呆错图床系统源码图片CDN加速与破J防盗链功能
揭秘得物客服IM全链路通信过程
Qt官方示例:Qt Quick Controls - Gallery
Leetcode 面试题 16.17. 连续数列
【西北工业大学】考研初试复试资料分享
夜神模拟器+Fiddler抓包测试App
随机推荐
又一所双非改考408,会爆冷么?南昌航空大学软件学院
Web实时通信技术之Websocket
Summary of fun free GM games
@Component 拿不到dao层
A4988 and 42 stepper motors
MySQL 关于 only_full_group_by 限制
微信小程序视频分享平台系统毕业设计毕设(4)开题报告
工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座
2020 Internet industry terminology
Leetcode 面试题 16.17. 连续数列
Renren potential field method
Leetcode 面试题 17.04. 消失的数字
300+ documents! This article explains the latest progress of multimodal learning based on transformer
In early summer, Kaiyuan magic changed an electric mosquito racket with killing sound effect!
NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
快速排序基本思路(通俗易懂+例子)「建议收藏」
Simulateur nightGod + application de test de capture de paquets Fiddler
Night God simulator +fiddler packet capture test app
Vi/vim delete: one line, one character, word, the first character of each line command
微信小程序视频分享平台系统毕业设计毕设(7)中期检查报告