Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fbe928d

Browse files
authoredJun 7, 2020
Create calculate-salaries.sql
1 parent 86fdcea commit fbe928d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

‎MySQL/calculate-salaries.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(m + n)
2+
# Space: O(m + n)
3+
4+
SELECT s.company_id,
5+
s.employee_id,
6+
s.employee_name,
7+
ROUND(s.salary * t.rate) salary
8+
FROM Salaries s
9+
INNER JOIN
10+
(SELECT company_id,
11+
CASE
12+
WHEN MAX(salary) < 1000 THEN 1.0
13+
WHEN MAX(salary) <= 10000 THEN 0.76
14+
ELSE 0.51
15+
END AS rate
16+
FROM Salaries
17+
GROUP BY company_id
18+
ORDER BY NULL) t ON s.company_id = t.company_id;
19+

0 commit comments

Comments
 (0)
Please sign in to comment.