当前位置:   article > 正文

LeetCode题解(0579):查询员工的累计薪水(SQL)

LeetCode题解(0579):查询员工的累计薪水(SQL)

题目:原题链接(困难)

标签:SQL

解法时间复杂度空间复杂度执行用时
Ans 1 (Python)336ms (22.34%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

SELECT E1.Id AS Id,
       E1.Month AS Month,
       (IFNULL(E1.Salary, 0) + IFNULL(E2.Salary, 0) + IFNULL(E3.Salary, 0)) AS Salary
FROM Employee AS E1
         LEFT JOIN
     Employee AS E2 ON (E2.Id = E1.Id AND E2.Month = E1.Month - 1)
         LEFT JOIN
     Employee AS E3 ON (E3.Id = E1.Id AND E3.Month = E1.Month - 2)
WHERE (E1.Id, E1.Month) NOT IN (SELECT Id, MAX(Month)
                                FROM Employee
                                GROUP BY Id)
ORDER BY E1.Id, E1.Month DESC;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/950234
推荐阅读
相关标签
  

闽ICP备14008679号