Revising Aggregations - The Sum Function | HackerRank
Query the total population of all cities for in the District of California.
www.hackerrank.com
쿼리가 짧고 간단한게 연속으로 나와서, 하나의 포스트에 정리하겠다.
Revising Aggregations - The Sum Function
Query the total population of all cities in CITY where District is California.
Input Format
The CITY table is described as follows:
SELECT SUM(POPULATION)
FROM CITY
WHERE DISTRICT ='California'
Revising Aggregations - AVERAGES
Query the average population of all cities in CITY where District is California.
SELECT AVG(POPULATION)
FROM CITY
WHERE DISTRICT ='California'
Revising Aggregations - Average Population
Query the average population for all cities in CITY, rounded down to the nearest integer.
# 정수일때는 round (원하는 숫자, 0)
# 수수점이 늘어갈때마다 1씩 뒤에 추가
SELECT ROUND(AVG(POPULATION),0)
FROM CITY
Revising Aggregations - Japan Population
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'
Revising Aggregations - Population Density Difference
Query the difference between the maximum and minimum populations in CITY.
SELECT MAX(POPULATION)-MIN(POPULATION)
FROM CITY
간단하게 계산하는 함수들 쓰는걸 한번 집고 넘어가는 느낌이다.
'Code Problems > SQL_ HackerRank' 카테고리의 다른 글
[Hacker Rank] Top Earners (0) | 2021.11.07 |
---|---|
[HackerRank] The Blunder (0) | 2021.11.07 |
[HackerRank] Revising Aggregations - The Count Function (0) | 2021.11.07 |
[HackerRank] New Company (0) | 2021.11.06 |
[HackerRank] Binary Tree Nodes (0) | 2021.11.06 |