Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db833fb

Browse files
authored
Update 579. Find Cumulative Salary of an Employee.sql
1 parent 5688ba1 commit db833fb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

‎hard/579. Find Cumulative Salary of an Employee.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ SELECT id,month,salary
1212
FROM cte
1313
WHERE row_num<count
1414
ORDER BY id,month DESC;
15+
16+
----------------------------- OR -----------------------------
17+
18+
SELECT e1.id,e1.month,SUM(e2.salary)
19+
FROM employee_579 e1
20+
JOIN employee_579 e2 ON e1.id = e2.id AND e1.month - e2.month BETWEEN 0 AND 2
21+
WHERE (e1.id,e1.month) NOT IN (SELECT id,MAX(MONTH) FROM employee_579 GROUP BY id)
22+
GROUP BY e1.id,e1.month
23+
ORDER BY e1.id,e1.month DESC;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /