sql notes: hackerrank average population

Problem


Query the average population for all cities in CITY, rounded down to the nearest integer.

Input Format
The CITY table is described as follows:

CITY

Field Type
ID NUMBER
NAME VARCHAR2(17)
COUNTRYCODE VARCHAR2(3)
DISTRICT VARCHAR2(20)
POPULATION NUMBER

Analysis


  • query average population ==> SELECT AVG(POPULATION)
  • round down to the nearest integer ==> SELECT ROUND(AVG(POPULATION))
  • in CITY table ==> FROM CITY

Solution


1
SELECT ROUND(AVG(POPULATION)) FROM CITY;

Average Population
(中文版) SQL 笔记: Hackerrank Average Population