How to find the proportion of zones for each neighbourhood using psql?

爱⌒轻易说出口 提交于 2019-12-25 07:18:51

问题


I have a table with Neighbourhood, Zones and Lot size. How to find the proportion of zones in Each neighbourhood using Lot size ??

This is my table:

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

回答1:


This should work:

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;

(Modified from my answer to my own question here.)



来源:https://stackoverflow.com/questions/38302106/how-to-find-the-proportion-of-zones-for-each-neighbourhood-using-psql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!