AC solution using join


  • 1
    R
    select A.pay_m pay_month, A.department_id,IF(A.amt=B.amt,'same',if(A.amt>b.amt,'higher','lower') ) comparison from 
    
    (select pay_m, department_id, avg(amount) amt from (select *,left(pay_date,7) pay_m from 
    salary) S join employee E on S.employee_id = E.employee_id group by pay_m, department_id)   A
    
    join
    
    (select pay_m, avg(amount) amt from (select *,left(pay_date,7) pay_m from salary) T1 group by pay_m) B 
    
    on A.pay_m = B.pay_m
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.