首页 > 其他 > 详细

615 Average Salary: Departments VS Company

时间:2018-10-23 13:03:21      阅读:160      评论:0      收藏:0      [点我收藏+]

https://leetcode.com/articles/average-salary-departments-vs-company/

select date_formate(pay_date,‘%Y-%m‘) pay_month, e.department_id,

  (case when avg(amount) = com_avg  then ‘same‘

  when avg(amount) > com_avg  then ‘higher‘

  else ‘lower‘ end) comparison  

from salary s1

left join employee e on s.employee_id  = e.employee_id 

inner join

(select date_format(pay_date, ‘%Y-%m‘pay_month, avg(amount) com_avg from salary group by date_formate(pay_date,‘%Y-%m‘)) s2

on s2.pay_month= date_formate(s1.pay_date,‘%Y-%m‘)

group by e.department_id,date_formate(pay_date,‘%Y-%m‘)

 

615 Average Salary: Departments VS Company

原文:https://www.cnblogs.com/ffeng0312/p/9835625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!