如何使用psql查找每个邻域的区域比例?

时间:2016-07-11 08:12:55

标签: psql

我有一个包含邻域,区域和地块大小的表格。如何使用批量大小找到每个社区的区域比例

这是我的表:

Neighbourhood    Zones    Lotsize
Albany           RSL      415
Albany           RSL      410
Albany           PU       34621
Abbottsfield     RF5      24267
Abbottsfield     AP       9745
Abbottsfield     CSC      57799

1 个答案:

答案 0 :(得分:0)

这应该有效:

SELECT
    p.Neighbourhood,
    p.Zones,
    (CAST(COUNT(p.*) AS FLOAT) / CAST(
        (SELECT
            COUNT(*)
        FROM properties AS p1
        WHERE p1.Neighbourhood=p.Neighbourhood) AS FLOAT)
    ) AS proportion
FROM properties AS p
GROUP BY p.Neighbourhood, p.Zones;

(根据我对自己的问题here的回答修改。)