Regarding this answer:
SELECT f.name country, c.urban_pop, f.population total_pop, (c.urban_pop / CAST(f.population AS FLOAT)) urban_pct FROM facts f INNER JOIN ( SELECT facts_id, SUM(population) urban_pop FROM cities GROUP BY 1 ) c ON c.facts_id = f.id WHERE urban_pct > .5 ORDER BY 4 ASC;
…and specifically this part:
(c.urban_pop / CAST(f.population AS FLOAT)) urban_pct
In general, why is casting to float necessary here?
f.population are INT to begin with correct?
Dividing INT by INT is bad somehow? Why?
In this case, the divisor was casted to float. Does it have to be the divisor or could it be the dividend instead?
When I submitted my answer, I casted both the dividend and the divisor as float but I can see that wasn’t necessary?
Thank you for your time!