题解 | #统计出当前各个title类型对应的员工当前薪水对应的平均工资#

统计出当前各个title类型对应的员工当前薪水对应的平均工资

http://www.nowcoder.com/practice/c8652e9e5a354b879e2a244200f1eaae

  • 开窗函数
    Mysql 8.0以上才可以。
    select distinct t.title, avg(s.salary) over (partition by t.title) as `avg(s.salary)`
    from titles as t inner join salaries s
      on t.emp_no = s.emp_no
    order by `avg(s.salary)`;
  • 组合查询
    查询表包含emp_no、title和salary(当前值)
    select s.emp_no, t.title, s.salary
    from titles as t
           left join salaries as s
                     on t.emp_no = s.emp_no
    where t.to_date = '9999-01-01'
    and s.to_date = '9999-01-01';
    计算字段
    select title, avg(salary)
    from (select t.title, s.salary
        from titles as t
                 left join salaries as s
                           on t.emp_no = s.emp_no
        where t.to_date = '9999-01-01'
          and s.to_date = '9999-01-01') as a1
    group by title;
全部评论

相关推荐

11.10晚上7点,重复了,都是技术开发,选哪个好
许愿给个offer吧吧:中移吧,建信金科我听说很多人是先面试完的了
点赞 评论 收藏
分享
09-12 15:03
已编辑
台州学院 材料工程师
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务