码迷,mamicode.com
首页 > 其他好文 > 详细

615 Average Salary: Departments VS Company

时间:2018-10-23 14:48:35      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:lower   dep   bsp   from   form   company   nts   sele   format   

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

标签:lower   dep   bsp   from   form   company   nts   sele   format   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!