HackerRank SQL
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:
Logic:
The only tricky thing here is “rounded down to the nearest integer”.
The syntax is to use FLOOR().
CEIL(): Return the smallest integer value that is greater than or equal to the value
FLOOR(): Return the largest integer value that is equal to or less than the value
Solution:
SELECT FLOOR(AVG(POPULATION)) FROM CITY;