1. Revising the Select Query 1
2. Revising the Select Query 2
3. Select All
4. Select By ID
5. Average Population
6. Population Density Difference
7. Japan Population
8. Japanese Cities’ Names
9. Japanese Cities’ Attributes
1. Revising the Select Query 1
SELECT * -- all columns
FROM city -- city table
WHERE population > 100000 AND countrycode = 'USA';
- population이 100000보다 크면서 (AND) countrycode가 'USA'인 조건을 WHERE절에 추가
2. Revising the Select Query 2
SELECT name
FROM city
WHERE population > 120000 AND countrycode = 'USA';
- population이 120000보다 크면서 (AND) countrycode가 'USA'인 조건을 WHERE절에 추가
3. Select All
SELECT *
FROM CITY;
4. Select By ID
SELECT *
FROM CITY
WHERE ID = 1661;
5. Average Population
SELECT FLOOR(AVG(population))
FROM city;
- 버림을 하라고했으므로 FLOOR 함수를 사용해준다.
6. Population Density Difference
SELECT MAX(population) - MIN(population)
FROM city;
- 최댓값 구하기 MAX함수 / 최솟값 구하기 MIN 함수
7. Japan Population
SELECT SUM(population)
FROM city
WHERE countrycode = 'JPN';
- population의 합계를 구해야하므로 SUM(population)
- countrycode가 'JPN'이라는 조건을 where절에 추가
8. Japanese Cities' Names
SELECT name
FROM city
WHERE countrycode = 'JPN';
- countrycode가 'JPN'인 조건을 주고 name 컬럼을 SELECT 했다.
9. Japanese Cities' Attributes
SELECT *
FROM city
WHERE countrycode = 'JPN';
'SQL > SQL 문제' 카테고리의 다른 글
[SQL] HackerRank - Placements(M) (0) | 2022.06.01 |
---|---|
[SQL] HackerRank - The Report(M) (0) | 2022.06.01 |
[SQL] HackerRank - Blunder, Census, African, 75 Marks(E) (0) | 2022.05.19 |
[SQL] HackerRank - Employee, Revising 5문제(E) (0) | 2022.05.17 |
[MySQL] 프로그래머스 SQL 고득점 Kit (0) | 2022.02.28 |