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 55ecdad

Browse files
author
Shuo
authored
Merge pull request #284 from openset/develop
Add: README
2 parents 5b1f080 + 75cec19 commit 55ecdad

File tree

2 files changed

+89
-2
lines changed
  • problems
    • binary-tree-vertical-order-traversal
    • find-cumulative-salary-of-an-employee

2 files changed

+89
-2
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
## 314. Binary Tree Vertical Order Traversal
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
27

8+
## 314. Binary Tree Vertical Order Traversal (Medium)
9+
10+
11+
12+
### Related Topics
13+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
14+
15+
### Similar Questions
16+
1. [Binary Tree Level Order Traversal](https://github.com/openset/leetcode/tree/master/problems/binary-tree-level-order-traversal) (Medium)
Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
## 579. Find Cumulative Salary of an Employee
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
27

8+
## 579. Find Cumulative Salary of an Employee (Hard)
9+
10+
<p>The <b>Employee</b> table holds the salary information in a year.</p>
11+
12+
<p>Write a SQL to get the cumulative sum of an employee's salary over a period of 3 months but exclude the most recent month.</p>
13+
14+
<p>The result should be displayed by 'Id' ascending, and then by 'Month' descending.</p>
15+
16+
<p><b>Example</b><br />
17+
<b>Input</b>
18+
<pre>
19+
| Id | Month | Salary |
20+
|----|-------|--------|
21+
| 1 | 1 | 20 |
22+
| 2 | 1 | 20 |
23+
| 1 | 2 | 30 |
24+
| 2 | 2 | 30 |
25+
| 3 | 2 | 40 |
26+
| 1 | 3 | 40 |
27+
| 3 | 3 | 60 |
28+
| 1 | 4 | 60 |
29+
| 3 | 4 | 70 |
30+
</pre>
31+
32+
<b>Output</b>
33+
<pre>
34+
35+
| Id | Month | Salary |
36+
|----|-------|--------|
37+
| 1 | 3 | 90 |
38+
| 1 | 2 | 50 |
39+
| 1 | 1 | 20 |
40+
| 2 | 1 | 20 |
41+
| 3 | 3 | 100 |
42+
| 3 | 2 | 40 |
43+
</pre>
44+
</p>
45+
46+
<b>Explanation</b>
47+
<p>Employee '1' has 3 salary records for the following 3 months except the most recent month '4': salary 40 for month '3', 30 for month '2' and 20 for month '1'</br>
48+
So the cumulative sum of salary of this employee over 3 months is 90(40+30+20), 50(30+20) and 20 respectively.</p>
49+
<pre>
50+
| Id | Month | Salary |
51+
|----|-------|--------|
52+
| 1 | 3 | 90 |
53+
| 1 | 2 | 50 |
54+
| 1 | 1 | 20 |
55+
</pre>
56+
57+
Employee '2' only has one salary record (month '1') except its most recent month '2'.
58+
<pre>
59+
| Id | Month | Salary |
60+
|----|-------|--------|
61+
| 2 | 1 | 20 |
62+
</pre></p>
63+
Employ '3' has two salary records except its most recent pay month '4': month '3' with 60 and month '2' with 40. So the cumulative salary is as following.
64+
<pre>
65+
| Id | Month | Salary |
66+
|----|-------|--------|
67+
| 3 | 3 | 100 |
68+
| 3 | 2 | 40 |
69+
</pre></p>
70+
71+
### Hints
72+
1. Seem hard at first glance? Try to divide this problem into some sub-problems.
73+
Think about how to calculate the cumulative sum of one employee, how to get the cumulative sum for many employees, and how to except the most recent month of the result.
74+
1. Use the technique of self-join if you have only one table but to write a complex query.
75+
1. Still remember how to use the function `sum` and `max`?

0 commit comments

Comments
(0)

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