题解 | 统计各个部门平均薪资

统计各个部门平均薪资

https://www.nowcoder.com/practice/4722fdf89a4c43eebb58d61a19ccab31

select staff_tb.department, (round(sum(salary_tb.normal_salary-salary_tb.dock_salary)/count(staff_tb.staff_id),3)) as avg_salary
         from staff_tb join salary_tb on staff_tb.staff_id=salary_tb.staff_id
         where (salary_tb.normal_salary - salary_tb.dock_salary) between 4000 and 30000
         group by staff_tb.department
         order by avg_salary desc;

最开始TEST了很久出不来的原因是SQL 中不支持连续的比较运算符(如 a <= b <= c),这种写法在数学中合法,但在 SQL 中会导致语法解析错误。

用了(salary_tb.normal_salary - salary_tb.dock_salary) between 4000 and 30000改写即可。

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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