当前位置:网站首页>Daily sql-seek the sum of successful investments in 2016

Daily sql-seek the sum of successful investments in 2016

2022-08-11 07:13:00 Eating too much sugar will not gain weight

Daily sql-find the sum of successful investments in 2016

Background

Conditions for successful investment in 2016:
1. The insured amount in 2015 is at least the same as the amount insured by another insured in 2015
2. The coordinates of this insured must be unique.

DDL

CREATE TABLE IF NOT EXISTS insurance (PID INTEGER(11), TIV_2015 NUMERIC(15,2), TIV_2016 NUMERIC(15,2), LAT NUMERIC(5,2), LON NUMERIC(5,2span>) );insert into insurance (PID, TIV_2015, TIV_2016, LAT, LON) values ​​(1, 10, 5, 10, 10);insert into insurance (PID, TIV_2015, TIV_2016, LAT, LON) values ​​(2, 20,20, 20, 20);insert into insurance (PID, TIV_2015, TIV_2016, LAT, LON) values ​​(3, 10, 30, 20, 20span>);insert into insurance (PID, TIV_2015, TIV_2016, LAT, LON) values ​​(4,10, 40, 40, 40);

insert image description here

sql

insert image description here

SELECT SUM(insurance.TIV_2016) AS TIV_2016FROM insuranceWHERE 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 );
原网站

版权声明
本文为[Eating too much sugar will not gain weight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110517396415.html