员工部门mysql面试题
来源:互联网 发布:阿里云测试培训 编辑:程序博客网 时间:2024/06/05 00:09
员工部门工资SQL面试题
现有employee 表,表中有 员工编号(id) 员工年龄(age) 员工工资(salary) 员工部门(deptid), 按要求用一条SQL语句完成
create table employee(
id int identity(1,1) primary key ,
name varchar(50),
salary bigint,
deptid int);
1.查出每个部门高于部门平均工资的员工名单
select ta.* from employee ta,
(select deptid,avg(salary) avgsal from employee group by deptid)tb
where ta.deptid=tb.deptid and ta.salary>tb.avgsal
2、列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序。
select ta.deptid,count(*) as ‘人数’ from employee ta,
(select deptid,avg(salary) avgsal from employee group by deptid)tb
where ta.deptid=tb.deptid and ta.salary>tb.avgsal group by ta.deptid order by ta.deptid
3.求每个部门工资不小于6000的人员的平均值;
SELECT avg(salary) as ‘平均值’,deptid FROM employee where salary >=6000 GROUP BY dept_id
4、各部门在各年龄段的平均工资
select deptid,
sum(case when age < 20 then salary else 0 end) / sum(case when age <20 then 1 else 0 end) as “20岁以下平均工资”,
sum(case when age >= 20 and age <40 then salary else 0 end) / sum(case when age >= 20 and age <40 then 1 else 0 end) as “20至40岁平均工资”,
sum(case when age >= 40 then salary else 0 end) / sum(case when age >=40 then 1 else 0 end) as “>40岁及以上平均工资”,
from employee
group by deptid
- 员工部门mysql面试题
- 员工部门工资SQL面试题
- 员工部门工资SQL面试题
- 面试题:查询部门最高工资的员工信息
- MySQL 部门 员工数量查询
- 员工综合素质面试题整理和收集
- Hibernate 员工和部门
- 获得员工部门
- 百度开发工程师的面试题(导航部门)
- 查询部门(包含子部门)员工
- MYSQL面试题
- Mysql面试题精选
- mysql面试题集锦
- MySql面试题
- mysql一道面试题
- Mysql面试题精选
- mysql面试题
- mysql经典面试题
- Hadoop、spark的一些基本使用笔记
- SVM算法
- mySql的连接useSSL=false
- android 应用重启实现
- pandas.DataFrame.append
- 员工部门mysql面试题
- 单片机与数字电路抗干扰措施
- java1.8 lambda表达式 函数式编程 闭包
- Canvas基础知识
- C++中的Compare()函数用法
- Android工程方法数超过65535,怎么破
- 赫夫曼编码
- 重新搭建eclipse、android、tomcat平台
- Android 仿火萤视频桌面 神奇的LiveWallPaper