Revising Aggregations - The Count Function
Query a count of the number of cities in CITY having a Population larger than 100,000.
Input Format
The CITY table is described as follows:
인구가 100,000보다 큰 CITY의 도시 수를 쿼리합니다.
SELECT COUNT(*) ➡ 수를 세어라
FROM CITY ➡ CITY테이블에서
WHERE POPULATION > 100000 ➡ 인구가 100,000초과인
Revising Aggregations - The Sum Function
Query the total population of all cities in CITY where District is California.
지역구가 캘리포니아인 CITY의 모든 도시의 총 인구를 쿼리합니다.
SELECT SUM(POPULATION) ➡ 인구의 합
FROM CITY ➡ CITY테이블로 부터
WHERE DISTRICT = 'California' ➡ DISTRICT가 'california'인
Revising Aggregations - Averages
Query the average population of all cities in CITY where District is California.
지역구가 캘리포니아인 CITY의 모든 도시의 평균 인구를 쿼리합니다.
SELECT AVG(POPULATION) ➡ 인구의 평균
FROM CITY ➡ CITY 테이블로 부터
WHERE DISTRICT = 'California' ➡ 지역구가 'California'인
Average Population
Query the average population for all cities in CITY, rounded down to the nearest integer.
CITY에 있는 모든 도시의 평균 인구를 가장 가까운 정수로 반올림하여 쿼리합니다.
SELECT ROUND(AVG(POPULATION)) ➡ 반올림 한 인구의 평균
FROM CITY ➡ CITY테이블에서
Japan Population
Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN.
CITY에 있는 모든 일본 도시의 인구 합계를 쿼리합니다. 일본의 국가 코드는 일본입니다.
SELECT SUM(POPULATION) ➡ 인구의 합계
FROM CITY WHERE COUNTRYCODE = 'JPN' ➡ COUNTRYCODE가 JPN인
Population Density Difference
Query the difference between the maximum and minimum populations in CITY.
POPULATION의 최댓값과 최솟값의 차이
SELECT MAX(POPULATION) - MIN(POPULATION) FROM CITY
The Blunder
Samantha was tasked with calculating the average monthly salaries for all employees in the EMPLOYEES table, but did not realize her keyboard's key was broken until after completing the calculation. She wants your help finding the difference between her miscalculation (using salaries with any zeros removed), and the actual average salary.
Write a query calculating the amount of error (i.e.: actual-miscalculated average monthly salaries), and round it up to the next integer.
사만다는 직원 테이블에 있는 모든 직원들의 평균 월급을 계산하는 임무를 맡았지만 계산을 마치고 나서야 키보드의 키가 부러진 것을 깨달았다.
그녀는 자신의 계산 착오(0이 제거된 급여 사용)와
실제 평균 급여 사이의 차이를 찾는 데 도움이 필요하다고 합니다.
오류 금액(즉, 실제 잘못 계산된 평균 월 급여)을 계산하는 쿼리를 작성하고 다음 정수로 반올림합니다.
SELECT CEIL(AVG(salary) - AVG(replace(salary,0,'')))
FROM employees
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 2space-separated integers.
Input Format
The Employee table containing employee data for a company is described as follows:
우리는 직원의 총 수입을 매월로 정의한다
급여 * 근무 개월 수,
직원 표에 있는 직원의 최대 총 소득이 될 수 있는 최대 총 소득.
쿼리를 작성하여 모든 직원의 최대 총 수입과 최대 총 수입을 가진 직원의 총 수를 찾습니다.
그런 다음 이 값을 2개의 공백으로 구분된 정수로 인쇄합니다.
SELECT SALARY * MONTHS AS ANSWER, ➡ ANSWER 별칭 사용, MONTH * SALARY
COUNT(*)FROM EMPLOYEE ➡ EMPLOYEE 테이블로 부터
GROUP BY ANSWER ➡ ANSWER로 묶어준다
ORDER BY ANSWER DESC ➡ 내림차순 정렬
LIMIT 1 ➡ 최상위 값 추출