본문 바로가기
CODING TEST/SQL : HackerRank

[MySQL] Average Population

by 주 녕 2021. 4. 21.
728x90

▶ SQL  >  Aggregation  > 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: 

 My Answer 

SELECT ROUND(AVG(POPULATION))
FROM CITY

 

 NOTE 

  • ROUND 함수 : 반올림
    • ROUND(컬럼명) - 소수점 1번째 자리에서 반올림 (123.7 → 124)
    • ROUND(컬럼명, 1) - 출력할 소수점 자리 지정 (123.75 → 123.8)
    • ROUND(컬럼명, -1) - 10단위로 반올림 (123 → 120)
  • TRUNCATE 함수 : 버림
    • TRUNCATE(컬럼명, 1) - 반드시 버릴 자릿수 명시해야 함
  • FLOOR 함수 : 버림
    • FLOOR(컬럼명) - 소수점 아래 버림

 

 

 

728x90

'CODING TEST > SQL : HackerRank' 카테고리의 다른 글

[MYSQL] Top Earners  (0) 2021.05.26
[MYSQL] The Blunder  (0) 2021.05.18
[MYSQL] Population Density Difference  (0) 2021.05.13
[MYSQL] Japan Population  (0) 2021.05.13
[MySQL] Revising Aggregations - Averages  (0) 2021.04.20
[MySQL] Revising Aggregations - The Count Function  (0) 2021.04.20
[MySQL] Employee Salaries  (0) 2021.04.15
[MySQL] Employee Names  (0) 2021.04.15

댓글