615. Average Salary: Departments VS Company
Posted yuesi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了615. Average Salary: Departments VS Company相关的知识,希望对你有一定的参考价值。
# Write your mysql query statement below
SELECT d.pay_month,department_id,
IF(department_avg=company_avg,‘same‘,IF(department_avg>company_avg,‘higher‘,‘lower‘)) AS comparison
FROM (SELECT date_format(s.pay_date,‘%Y-%m‘) pay_month,
e.department_id,
avg(amount) AS department_avg
FROM salary s
LEFT JOIN employee e
ON s.employee_id = e.employee_id
GROUP BY pay_month,e.department_id) d
JOIN
(SELECT date_format(pay_date,‘%Y-%m‘) AS pay_month,
avg(amount) AS company_avg
FROM salary
GROUP BY pay_month) c
ON d.pay_month = c.pay_month
ORDER BY department_id
;
以上是关于615. Average Salary: Departments VS Company的主要内容,如果未能解决你的问题,请参考以下文章
1491. Average Salary Excluding the Minimum and Maximum Salary
LeetCode --- 1491. Average Salary Excluding the Minimum and Maximum Salary 解题报告
LeetCode --- 1491. Average Salary Excluding the Minimum and Maximum Salary 解题报告