sql - Min function in postgresql -
i trying find division lowest population density did following:
select p.edname, min((p.total_area*1000)/p.total2011) "lowest population density" eds_census2011 p group p.edname having count (*)> 1
total_area
multiplied 1000 (so in square metres) , divide total population. want 1 record displaying division (edname
) , population density wich calculated (min((p.total_area*1000)/p.total2011))
, instead records - not sorted...
the problem have group edname, if leave out group by
, having
lines error. appriciated!
try
select edname, (total_area*1000/total2011) density eds_census2011 (total_area*1000/total2011) = (select min(total_area*1000/total2011) eds_census2011)
a 'return 1 row' rule enforced using limit 1
if it's necessary
Comments
Post a Comment