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

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

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

# 方法二:
# 按最小颗粒度进行细分聚合之后,再按部门进行聚合模糊了性别
# 按性别加权平均反推出员工综合平均薪资
select department,
round(sum(total)/sum(nums),2) average_actual_salary,
round(sum(average_salary_male),2) average_actual_salary_male,
round(sum(average_salary_female),2)average_actual_salary_female
from(
    select department,
staff_gender,
sum(normal_salary-dock_salary) total,
count(s.staff_id) nums,
if(staff_gender = 'male',sum(normal_salary-dock_salary)/count(s.staff_id),0.00) average_salary_male,
if(staff_gender = 'female',sum(normal_salary-dock_salary)/count(s.staff_id),0.00) average_salary_female
from staff_tb s
left join salary_tb a on s.staff_id = a.staff_id
group by department,staff_gender
) t1
group by department
order by average_actual_salary desc

全部评论

相关推荐

秋盈丶:后续:我在宿舍群里和大学同学分享了这事儿,我好兄弟气不过把他挂到某脉上了,10w+阅读量几百条评论,直接干成精品贴子,爽
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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