当前位置:   article > 正文

LeetCode-SQL-579. 查询员工的累计薪水_sql语句查询员工累计薪水

sql语句查询员工累计薪水

  1. SELECT
  2. E1.id,
  3. E1.month,
  4. (IFNULL(E1.salary, 0) + IFNULL(E2.salary, 0) + IFNULL(E3.salary, 0)) AS Salary
  5. FROM
  6. (SELECT
  7. id, MAX(month) AS month
  8. FROM
  9. Employee
  10. GROUP BY id
  11. HAVING COUNT(*) > 1) AS e
  12. LEFT JOIN
  13. Employee E1 ON (e.id = E1.id
  14. AND e.month > E1.month)
  15. LEFT JOIN
  16. Employee E2 ON (E2.id = E1.id
  17. AND E2.month = E1.month - 1)
  18. LEFT JOIN
  19. Employee E3 ON (E3.id = E1.id
  20. AND E3.month = E1.month - 2)
  21. ORDER BY id ASC , month DESC
  22. ;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/950190
推荐阅读
相关标签
  

闽ICP备14008679号