1
I am using postgresql
I have a query that when I run a division between the columns (soma_neighborhood / Soma_city) it always returns 1, should return the value described in the field and not the count amount of the row, follows example.
I believe I’m wrong here :
(COUNT(distinct neighborhood) / COUNT(distinct tbl.city)) as percentual
How do I make her understand the value of the field and not the account?
SELECT
city,
neighborhood,
count(neighborhood) as Soma_bairros,
(select count(city) FROM tb_listings WHERE city = tbl.city) as Soma_cidade ,
(COUNT(distinct neighborhood) / COUNT(distinct tbl.city)) as percentual
FROM tb_listings tbl
GROUP BY city, neighborhood
ORDER BY city, neighborhood DESC
Resultado atual:
Percentage returns 100 and not 33 %
You would have to classify field as INT ?