We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There's some ambuiguity in the table data.....
A given country's population should match the sum of population of all the cities in that country......
Hence this query should also pass the test cases:
SELECT con,FLOOR(pop/cnt) from (SELECT Country.Continent as con,COUNT(*) as cnt,SUM(Country.Population) as pop from CITY JOIN COUNTRY ON City.CountryCode=Country.Code GROUP BY Country.Continent) tab1;
But only this does:
SELECT con,FLOOR(pop/cnt) from (SELECT Country.Continent as con,COUNT(*) as cnt,SUM(CITY.Population) as pop from CITY JOIN COUNTRY ON City.CountryCode=Country.Code GROUP BY Country.Continent) tab1;
Or Am I wrong somewhere....pls point it out if thats the case....
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Average Population of Each Continent
You are viewing a single comment's thread. Return to all comments →
There's some ambuiguity in the table data..... A given country's population should match the sum of population of all the cities in that country......
Hence this query should also pass the test cases:
SELECT con,FLOOR(pop/cnt) from (SELECT Country.Continent as con,COUNT(*) as cnt,SUM(Country.Population) as pop from CITY JOIN COUNTRY ON City.CountryCode=Country.Code GROUP BY Country.Continent) tab1;
But only this does:
SELECT con,FLOOR(pop/cnt) from (SELECT Country.Continent as con,COUNT(*) as cnt,SUM(CITY.Population) as pop from CITY JOIN COUNTRY ON City.CountryCode=Country.Code GROUP BY Country.Continent) tab1;
Or Am I wrong somewhere....pls point it out if thats the case....