반응형 CODING TEST32 [MYSQL] The Blunder ▶ SQL > Aggregation > The Blunder Problem Samantha was tasked with calculating the average monthly salaries for all employees in the EMPLOYEES table, but did not realize her keyboard's 0 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 .. 2021. 5. 18. [MYSQL] Population Density Difference ▶ SQL > Aggregation > Population Density Difference Problem Query the difference between the maximum and minimum populations in CITY. → 최대 POPULATION과 최소 POPULATION의 차이를 query 하라 Input Format The CITY table is described as follows: My Answer SELECT MAX(POPULATION) - MIN(POPULATION) FROM CITY NOTE MAX(필드명) : 필드값 중 가장 큰 값 MIN(필드명) : 필드값 중 가장 작은 값 문제에서 둘의 차이를 구하라고 했기 때문에 MAX 값에서 MIN 값을 빼주었다! 2021. 5. 13. [MYSQL] Japan Population ▶ SQL > Aggregation > Japan Population Problem Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN. Input Format The CITY table is described as follows: My Answer SELECT SUM(POPULATION) FROM CITY WHERE COUNTRYCODE = 'JPN' NOTE SUM(필드명) : 필드 값을 더할 때 사용하는 함수 COUNT(필드명) : NULL이 아닌 레코드의 수 COUNT(*)은 레코드의 개수를 나타내지만 SUM(*)은 오류 2021. 5. 13. [MySQL] Average Population ▶ 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) TRUNCA.. 2021. 4. 21. [MySQL] Revising Aggregations - Averages ▶ SQL > Aggregation > Revising Aggregations - Averages Problem Query the average population of all cities in CITY where District is California. Input Format The CITY table is described as follows: My Answer SELECT AVG(POPULATION) FROM CITY WHERE DISTRICT = 'California' 2021. 4. 20. [MySQL] Revising Aggregations - The Count Function ▶ SQL > Aggregation > Revising Aggregations - The Count Function Problem 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: My Answer SELECT COUNT(*) FROM CITY WHERE POPULATION > 100000 2021. 4. 20. 이전 1 2 3 4 5 6 다음 반응형