Investments in 2016
You can write a query to calculate the sum of tiv_2016
for policyholders who meet the given criteria by using a subquery to filter the rows. Here’s the query:
|
|
Explanation:
- The first subquery selects
tiv_2015
values that are repeated among policyholders, usingGROUP BY
andHAVING COUNT(tiv_2015) > 1
. - The second subquery selects unique
(lat, lon)
pairs, usingGROUP BY
andHAVING COUNT(CONCAT(lat, lon)) = 1
. - The main query filters rows based on these two subqueries, and then calculates the sum of
tiv_2016
, rounding to two decimal places usingROUND
.