0
I have a query that searches 2 values and when divided should return the percentage, but this with integer number.
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
Current result:
You would have to classify field as INT ?
Which one
SGBD
? What type of column dataneighborhood
?– Sorack
would be that CREATE TABLE tb_listings ( "advertiser_id" varchar, "listing_id" varchar, "portal" varchar, "city" varchar, "Neighbhoodor" varchar);
– user156915
Ah disguises. What the
SGBD
?– Sorack
Sorry postgre, I’m using the sql fiddle tool
– user156915
Pass the fiddle link then
– Sorack
http://sqlfiddle.com/#! 15/1d25e/316
– user156915
Ué, but the two sides of the division give 1, there will always return 1 even. You better explain what are your data and what you want to extract from them
– Sorack
Take Neighborhood from group by , will always give 1 , multiply by 100 to have in percentage.
– Motta