[해커랭크] Basic 6문제

june·2023년 3월 23일
0

SQL

목록 보기
8/31

Revising Aggregations - The Count Function

https://www.hackerrank.com/challenges/revising-aggregations-the-count-function

  • Query a count of the number of cities in CITY having a Population larger than 100,000.
SELECT COUNT(name)
FROM city
WHERE population > 100000

Revising Aggregations - The Sum Function

https://www.hackerrank.com/challenges/revising-aggregations-sum

  • Query the total population of all cities in CITY where District is California.
SELECT SUM(population)
FROM city
WHERE district = 'California'

Revising Aggregations - Averages

https://www.hackerrank.com/challenges/revising-aggregations-the-average-function

  • Query the average population of all cities in CITY where District is California.
SELECT AVG(population)
FROM city
WHERE district = 'California'

Lesson & Learned

AVERAGE( ) 라는 함수는 SQL도 python에도 없다..!

Average Population

https://www.hackerrank.com/challenges/average-population

  • Query the average population for all cities in CITY, rounded down to the nearest integer.
SELECT FLOOR(AVG(population))
FROM city

Lesson & Learned

소수점 처리
CEIL( ) : 올림, FLOOR( ) : 내림

Japan Population

https://www.hackerrank.com/challenges/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'

Population Density Difference

https://www.hackerrank.com/challenges/population-density-difference

  • Query the difference between the maximum and minimum populations in CITY.
SELECT MAX(population) - MIN(population)
FROM city
profile
나의 계절은

0개의 댓글