Skip to content

Commit f679fb0

Browse files
committed
feat: add solutions to lc problems: No.0579,0585
* No.0579.Find Cumulative Salary of an Employee * No.0585.Investments in 2016
1 parent bb02b52 commit f679fb0

File tree

6 files changed

+120
-4
lines changed

6 files changed

+120
-4
lines changed

solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,30 @@
8888
### **SQL**
8989

9090
```sql
91-
91+
# Write your MySQL query statement below
92+
select
93+
id,
94+
month,
95+
sum(salary) over (
96+
partition by id
97+
order by
98+
month range 2 preceding
99+
) as Salary
100+
from
101+
employee
102+
where
103+
(id, month) not in (
104+
select
105+
id,
106+
max(month)
107+
from
108+
Employee
109+
group by
110+
id
111+
)
112+
order by
113+
id,
114+
month desc
92115
```
93116

94117
<!-- tabs:end -->

solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,30 @@ So the cumulative salary summary for this employee is:
113113
### **SQL**
114114

115115
```sql
116-
116+
# Write your MySQL query statement below
117+
select
118+
id,
119+
month,
120+
sum(salary) over (
121+
partition by id
122+
order by
123+
month range 2 preceding
124+
) as Salary
125+
from
126+
employee
127+
where
128+
(id, month) not in (
129+
select
130+
id,
131+
max(month)
132+
from
133+
Employee
134+
group by
135+
id
136+
)
137+
order by
138+
id,
139+
month desc
117140
```
118141

119142
<!-- tabs:end -->
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Write your MySQL query statement below
2+
select
3+
id,
4+
month,
5+
sum(salary) over (
6+
partition by id
7+
order by
8+
month range 2 preceding
9+
) as Salary
10+
from
11+
employee
12+
where
13+
(id, month) not in (
14+
select
15+
id,
16+
max(month)
17+
from
18+
Employee
19+
group by
20+
id
21+
)
22+
order by
23+
id,
24+
month desc

solution/0500-0599/0585.Investments in 2016/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,22 @@
6666
### **SQL**
6767

6868
```sql
69-
69+
# Write your MySQL query statement below
70+
with t as (
71+
select
72+
tiv_2016,
73+
count(pid) over(partition by tiv_2015) as cnt1,
74+
count(pid) over(partition by concat(lat, lon)) as cnt2
75+
from
76+
Insurance
77+
)
78+
select
79+
round(sum(TIV_2016), 2) tiv_2016
80+
from
81+
t
82+
where
83+
cnt1 != 1
84+
and cnt2 = 1;
7085
```
7186

7287
<!-- tabs:end -->

solution/0500-0599/0585.Investments in 2016/README_EN.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,22 @@ So, the result is the sum of tiv_2016 of the first and last record, which is 45.
7272
### **SQL**
7373

7474
```sql
75-
75+
# Write your MySQL query statement below
76+
with t as (
77+
select
78+
tiv_2016,
79+
count(pid) over(partition by tiv_2015) as cnt1,
80+
count(pid) over(partition by concat(lat, lon)) as cnt2
81+
from
82+
Insurance
83+
)
84+
select
85+
round(sum(TIV_2016), 2) tiv_2016
86+
from
87+
t
88+
where
89+
cnt1 != 1
90+
and cnt2 = 1;
7691
```
7792

7893
<!-- tabs:end -->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
tiv_2016,
5+
count(pid) over(partition by tiv_2015) as cnt1,
6+
count(pid) over(partition by concat(lat, lon)) as cnt2
7+
from
8+
Insurance
9+
)
10+
select
11+
round(sum(TIV_2016), 2) tiv_2016
12+
from
13+
t
14+
where
15+
cnt1 != 1
16+
and cnt2 = 1;

0 commit comments

Comments
 (0)