The Investments in 2016 interview question is a SQL filtering and summation task. You are given an Insurance table with investment values for 2015 and 2016, along with location coordinates (lat, lon). You need to sum the 2016 investment values for policyholders who meet two criteria:
TIV_2015 value as at least one other policyholder.lat, lon pair).Companies like Meta and Amazon ask the Investments in 2016 coding problem to test a candidate's ability to use Subqueries or Window Functions for complex filtering. It evaluation whether you can identify "duplicates" in one dimension while ensuring "uniqueness" in another. This is a core Database interview pattern for data reconciliation.
This problem uses Multiple Subquery Filtering.
WHERE TIV_2015 IN (SELECT TIV_2015 FROM Insurance GROUP BY TIV_2015 HAVING COUNT(*) > 1).AND (lat, lon) IN (SELECT lat, lon FROM Insurance GROUP BY lat, lon HAVING COUNT(*) = 1).SUM(TIV_2016) to the filtered rows.IN (SELECT ... GROUP BY ...) is much more direct and readable.Get comfortable with the GROUP BY ... HAVING pattern. It is the most robust way to find duplicates (count > 1) or unique items (count = 1) in a relational dataset.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Confirmation Rate | Medium | Solve | |
| Product Sales Analysis III | Medium | Solve | |
| Rank Scores | Medium | Solve | |
| Product Price at a Given Date | Medium | Solve | |
| Tree Node | Medium | Solve |