Skip to content

Commit 97ad079

Browse files
committed
Update 585. Investments in 2016.sql
1 parent 5340138 commit 97ad079

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

LeetCode SQL 50 Solution/585. Investments in 2016.sql

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
585. Investments in 2016
2-
Solved
3-
Medium
4-
Topics
5-
Companies
6-
Hint
7-
SQL Schema
8-
Pandas Schema
2+
"""
93
Table: Insurance
104
115
+-------------+-------+
@@ -58,4 +52,19 @@ The first record in the table, like the last record, meets both of the two crite
5852
The tiv_2015 value 10 is the same as the third and fourth records, and its location is unique.
5953
6054
The second record does not meet any of the two criteria. Its tiv_2015 is not like any other policyholders and its location is the same as the third record, which makes the third record fail, too.
61-
So, the result is the sum of tiv_2016 of the first and last record, which is 45.
55+
So, the result is the sum of tiv_2016 of the first and last record, which is 45.
56+
57+
"""
58+
59+
WITH
60+
InsuranceWithCounts AS (
61+
SELECT
62+
tiv_2016,
63+
COUNT(*) OVER(PARTITION by tiv_2015) AS tiv_2015_count,
64+
COUNT(*) OVER(PARTITION by lat, lon) AS city_count
65+
FROM Insurance
66+
)
67+
SELECT ROUND(SUM(tiv_2016), 2) AS tiv_2016
68+
FROM InsuranceWithCounts
69+
WHERE tiv_2015_count > 1
70+
AND city_count = 1;

0 commit comments

Comments
 (0)