我想在数据库mondial中写这个查询:
我写了这个查询:
select c.name, c.area, ai.sum_area
from country as c
inner join
(select sum(i.area) as sum_area, gi.country
from island i
inner join geo_island gi on (i.name = gi.island)
group by gi.country) as ai
on (c.code = ai.country)
where (c.area * 0.99) <= ai.sum_area;
但结果是错误的! 在一些国家,总和大于该国的岛屿面积! 我该如何纠正? 以下是mondial数据库中的文档:http://www.dbis.informatik.uni-goettingen.de/Mondial/ 和这里 Referential Dependencies of the Mondial Database
Country - area Country - Sum area islands
"Guernsey";194;194
"Iceland";103000;102829
"Ireland";70280;84421
"Jersey";117;117
"Isle of Man";588;588
"United Kingdom";244820;2622428.6
"Bahrain";620;620
"Brunei";5770;743122
"Malaysia";329750;1486335
"Christmas Island";135;135
"Cyprus";9251;9251
"Indonesia";1919440;10333702
"Timor-Leste";15007;33850
"Papua New Guinea";461690;794800
"Japan";377835;8247391
"Philippines";299764;1421325
"Singapore";632.6;632.6
"Sri Lanka";65610;65610
"Antigua and Barbuda";442;442
"Aruba";193;193
"Barbados";430;430
"Bermuda";53.3;53.3
"Cuba";110860;1481284
"Dominica";746;746
"Dominican Republic";48730;76192
"Haiti";27750;76192
"Greenland";2175600;2175600
"Grenada";344;344
"Jamaica";10991;10991
"Martinique";1128;1128
"Montserrat";102;102
"Curacao";444;444
"Sint Maarten";34;87
"Saint Martin";54;87
"Saint Barthelemy";21;21
"Puerto Rico";8870;8870
"Saint Lucia";620;616
"Trinidad and Tobago";5130;5128
"Guam";541.3;541
"Nauru";21;21
"New Zealand";268680;266354
"Niue";260;260
"Samoa";2860;2832
"Madagascar";587041;587041
"Mayotte";374;374
"Reunion";2510;2510
"Sao Tome and Principe";1001;1001
答案 0 :(得分:0)
您好,您可以尝试此查询
SELECT c.name. c.area, x.sum_area
FROM country c
INNER JOIN
(SELECT gi.country, SUM(i.area) as sum_area
FROM geo_island gi
INNER JOIN island i ON
gi.island = i.name
GROUP BY gi.country) x
ON c.name = x.country
WHERE (c.area * 0.99) <= x.sum_area;