P42 第08章_聚合函数 练习题

第08章_聚合函数 练习题

#1.where子句可否使用组函数进行过滤?

#不可以

#2.查询公司员工工资的最大值,最小值,平均值,总和

SELECT MAX(salary),MIN(salary),AVG(salary),SUM(salary)
FROM employees;

#3.查询各job_id的员工工资的最大值,最小值,平均值,总和

SELECT job_id,MAX(salary),MIN(salary),AVG(salary),SUM(salary)
FROM employees
GROUP BY job_id;

#4.选择具有各个job_id的员工人数

SELECT job_id,COUNT(employee_id)
FROM employees
GROUP BY job_id;

# 5.查询员工最高工资和最低工资的差距(DIFFERENCE)

SELECT MAX(salary)-MIN(salary)"difference"
FROM employees;

# 6.查询各个管理者手下员工的最低工资,其中最低工资不能低于6000,没有管理者的员工不计算在内

SELECT manager_id,MIN(salary)
FROM employees
WHERE manager_id IS NOT NULL
GROUP BY manager_id
HAVING MIN(salary)>=6000;

# 7.查询所有部门的名字,location_id,员工数量和平均工资,并按平均工资降序

SELECT d.department_name,d.location_id,COUNT(employee_id),AVG(salary)
FROM departments d LEFT OUTER JOIN employees e
ON d.`department_id`=e.`department_id`
GROUP BY department_name,location_id


SELECT employee_id,d.department_name,d.location_id
FROM departments d LEFT OUTER JOIN employees e
ON d.`department_id`=e.`department_id`

# 8.查询每个工种、每个部门的部门名、工种名和最低工资

SELECT d.department_name,e.job_id,MIN(salary)
FROM departments d LEFT OUTER JOIN employees e
ON d.`department_id`=e.`department_id`
GROUP BY department_name,job_id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值