mysql 错题集

1.查询各部门中工资比本部门平均工资高的员工的员工号,姓名和工资

①查询各部门的平均工资

SELECT AVG(salary),department_id
FROM employees
GROUP BY department_id;

mysql 错题集

②连接①结果集和employees表,进行筛选

SELECT employee_id,last_name,salary,e.department_id
FROM employees e
INNER JOIN (
	SELECT AVG(salary) ag ,department_id
	FROM employees
	GROUP BY department_id
)ag_dep
ON e.`department_id` = ag_dep.department_id
WHERE salary > ag;

mysql 错题集

上一篇:pyhton简单的购物车编码


下一篇:web前端day01