问题
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