관리 메뉴

TEAM EDA

[HackerRank] Basic Aggregation : Revising Aggregations 본문

EDA Study/SQL

[HackerRank] Basic Aggregation : Revising Aggregations

김현우 2021. 2. 9. 16:48

Input Format

The CITY table is described as follows:

Q1. Query the total population of all cities in CITY where Districtis California.

SELECT SUM(POPULATION) FROM CITY 
    WHERE DISTRICT = 'California'

Q2. Query the average population of all cities in CITY where District is California.

SELECT AVG(POPULATION) FROM CITY 
    WHERE DISTRICT = 'California'

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

SELECT FLOOR(AVG(POPULATION)) FROM CITY

Q4. Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN.

SELECT SUM(POPULATION) FROM CITY
    WHERE COUNTRYCODE = 'JPN'

Q5. Query the difference between the maximum and minimum populations in CITY.

SELECT MAX(POPULATION) - MIN(POPULATION) FROM CITY