-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path615.cpp
23 lines (13 loc) · 825 Bytes
/
615.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__________________________________________________________________________________________________
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')
__________________________________________________________________________________________________
__________________________________________________________________________________________________