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

SELECT 
    department, AVG(pay_salary) as avg_salary
FROM
    (
        SELECT 
            stt.department as department,
            (sat.normal_salary - sat.dock_salary) as pay_salary
        FROM
            staff_tb as stt
            LEFT JOIN salary_tb as sat ON stt.staff_id = sat.staff_id
        WHERE
            (sat.normal_salary - sat.dock_salary) BETWEEN 4000 AND 30000
        GROUP BY
            department,
            pay_salary
    ) as re
GROUP BY department
ORDER BY avg_salary DESC

# SQL_ERROR_INFO Not Select,总是遇到这个错误,记录一下,是由于牛客自动代码格式化的原因。在SELECT后面加一个空格就行

全部评论

相关推荐

不愿透露姓名的神秘牛友
2024-12-11 17:13
贝壳找房 软件开发 n*16
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2024-12-27 14:39
百度 后端开发 26*16 其他
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务