题解 | 各个部门实际平均薪资和男女员工实际平均薪资

各个部门实际平均薪资和男女员工实际平均薪资

https://www.nowcoder.com/practice/e8272685d07347cc88667f31f7989231

select  distinct department,
        round(avg(salary) over(partition by department),2) as average_actual_salary,
        round(coalesce(avg(case when staff_gender = 'male' then salary else null end) over(partition by department),0),2)   as average_actual_salary_male,
        round(coalesce(avg(case when staff_gender = 'female' then salary else null end) over(partition by department),0),2)   as average_actual_salary_female
from (
    select *,
          round(normal_salary - dock_salary,2) as salary 
    from staff_tb left join salary_tb using(staff_id)
) t 
order by average_actual_salary desc

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务