Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.
Question
Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.
Solution
To answer this question, you would need to join the CITY and COUNTRY tables on the appropriate column (likely COUNTRY_ID or similar), then group by CONTINENT, and finally calculate the average of the POPULATION column. Here is an example of how you might write this query in SQL:
SELECT COUNTRY.CONTINENT, FLOOR(AVG(CITY.POPULATION))
FROM CITY
JOIN COUNTRY ON CITY.COUNTRY_ID = COUNTRY.COUNTRY_ID
GROUP BY COUNTRY.CONTINENT;
Please replace COUNTRY_ID with the actual column that links the CITY and COUNTRY tables in your database.
This query works by first joining the CITY and COUNTRY tables together based on their common column (COUNTRY_ID). This creates a new table that includes columns from both CITY and COUNTRY. The GROUP BY clause then groups this table by CONTINENT. Finally, the AVG function calculates the average POPULATION for each group, and the FLOOR function rounds this down to the nearest integer.
Similar Questions
Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'.
Query the average population for all cities in CITY, rounded down to the nearest integer.
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.The CITY table is described as follows:
Big CountriesThere is a table WorldnamecontinentareapopulationgdpAfghanistanAsia6522302550010020343000AlbaniaEurope28748283174112960000AlgeriaAfrica238174137100000188681000AndorraEurope468781153712000AngolaAfrica124670020609294100990000A country is big if it has an area of bigger than 3 million square km or apopulation of more than 25 million.Write a SQL solution to output big countries' name, population and area.For example, according to the above table, we should output:namepopulationareaAfghanistan25500100652230Algeria371000002381741Optionsselect name, population, areawhere area >= 3000000 or population >= 25000000;select name, populationfrom Worldwhere area >= 3000000 or population >= 25000000;select name, population, areafrom Worldwhere area >= 3000000 or population >= 25;select name, population, areafrom Worldwhere area >= 3000000 or population >= 25000000;
Query the average population for all cities in CITY, rounded down to the nearest integer.Input FormatThe CITY table is described as follows: MySQL1select ceil(avg(population)) from city group by ID;Line: 1 Col: 12Run Code Submit CodeUpload Code as FileWrong Answer :(1/1 test case failedSample Test case 0Compiler MessageWrong AnswerYour Output (stdout)59332113562113140321092361003993000004703954201360139389961402523869323242326101295124300197408143726135825125244118080111866945261191043940968972328985225731520944216247214288910707817962689442428980028120001565800530000195485189293169400136811120000118858102384273140131717131097125997124116116178850000435964927003900581714951591039973486001019841376001860761024344000059951535900785071343361160516137400145900245772101100046940001410000563662202705124966121780120758117549922569123890555BlogScoringEnvironmentFAQAbout UsSupportCareersTerms Of ServicePrivacy Policy
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.