LeetCode-SQL-585. 2016年的投资

LeetCode-SQL-585. 2016年的投资_第1张图片

LeetCode-SQL-585. 2016年的投资_第2张图片

SELECT
    SUM(insurance.TIV_2016) AS TIV_2016
FROM
    insurance
WHERE
    insurance.TIV_2015 IN
    (
      SELECT
        TIV_2015
      FROM
        insurance
      GROUP BY TIV_2015
      HAVING COUNT(*) > 1
    )
    AND CONCAT(LAT, LON) IN
    (
      SELECT
        CONCAT(LAT, LON)
      FROM
        insurance
      GROUP BY LAT , LON
      HAVING COUNT(*) = 1
    )
;

 

你可能感兴趣的:(数据库,LeetCode)