【发布时间】:2018-03-12 17:30:14
【问题描述】:
我有一个表,即结算由 3 列和 5437 行组成。 第一列有 8 组(A、B、C、D、E、F、G、H),第二列有 '6' 组(City,Town,Village,Island,Suburb,Hamlet)强>
我的表如下...
ID district_name Cluster Population
1003 A village 1543
1002 B town 63437
1003 C village 1698
1002 D town 11785
1040 E hamlet 100
2034 F hamlet 190
4003 G city 207561
4243 H Suburb 682
674 D Island 718
1012 A village 1566
1040 F hamlet 200
1020 D town 11881
4055 D city 208763
我想根据以下条件计算每个地区的人口百分比;
total population in each district/sum(population)*100
where cluster='city' or cluster='town'
A practical example of my desire outpout can be as follows,
district_name Population_total(City+Town+island) Urban_Percentage(Town_City)
D 233147 99.69(232429/233147 * 100)
【问题讨论】:
-
“结果不正确”提供的帮助信息很少。结果是什么?样本数据?想要的结果?
-
您能给我们展示一些示例数据和预期结果吗?
-
我们无法从图像中复制/粘贴。将表格和数据发布为文本READ THIS您可以使用此工具senseful.github.io/text-table
-
请阅读How-to-Ask 这里是START 了解如何提高问题质量并获得更好答案的好地方。 How to create a Minimal, Complete, and Verifiable example 尝试在rextester.com 中创建样本
-
检查例如这个问题(模式、示例数据、预期输出):stackoverflow.com/questions/49257687/…
标签: sql postgresql