간략 정리
Id | Name | Visits |
1 | A | 1 |
2 | A | 2 |
3 | B | 3 |
4 | C | 5 |
5 | NULL | NULL |
COUNT
1 |
|
SUM
1 |
|
AVG
1 |
|
MAX/MIN
1 |
|
GROUP BY
1 |
|
(그룹화의 기준이 되는 컬럼은 SELECT 구문에 반드시 적어주기)
HAVING
1 |
|
ORDER BY
- 오름차순(Default)
- ASC ascending
- 내림차순
- DESC descending
1 |
|
LIMIT
1 |
|
(가장 비싼 물건 1개 출력)
해커랭크 문제 풀이
Average Population
- Query the average population for all cities in CITY, rounded down to the nearest integer.
- Input Format
- The CITY table is described as follows:
풀이
1 |
|
Revising Aggregations - The Sum Function
- Query the total population of all cities in CITY where District is California.
풀이
1 |
|
Revising Aggregations - Averages
- Query the average population of all cities in CITY where District is California.
풀이
1 |
|
Revising Aggregations - The Count Function
- Query a count of the number of cities in CITY having a Population larger than 100,000.
풀이
1 |
|
Population Density Difference
- Query the difference between the maximum and minimum populations in CITY.
풀이
1 |
|
Weather Observation Station 4
- Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
- The STATION table is described as follows:
풀이
1 |
|
Top Earners
- 문제 바로가기
- We define an employee’s total earnings to be their monthly salary * months worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as 2 space-separated integers.
- salary와 months를 곱하여 earnings를 생성한다.
- group by를 통해 최고 금액과 갯수를 구한다.
풀이
1 |
|