❓ Question https://www.hackerrank.com/challenges/average-population Average Population | HackerRank Query the average population of all cities, rounded down to the nearest integer. www.hackerrank.com ❗ Answer SELECT FLOOR(AVG(population)) FROM city; 📌 Discussion avg로 집계 후 floor로 버림
❓ Question https://www.hackerrank.com/challenges/revising-aggregations-the-average-function Revising Aggregations - Averages | HackerRank Query the average population of all cities in the District of California. www.hackerrank.com ❗ Answer SELECT AVG(population) FROM city WHERE district='California'; 📌 Discussion where로 조건에 맞는 레코드 불러온 후 avg로 집계
❓ Question https://www.hackerrank.com/challenges/revising-aggregations-sum Revising Aggregations - The Sum Function | HackerRank Query the total population of all cities for in the District of California. www.hackerrank.com ❗ Answer SELECT SUM(population) FROM city WHERE district='California'; 📌 Discussion where로 조건에 맞는 레코드 불러온 후 sum으로 집계
❓ Question https://www.hackerrank.com/challenges/average-population-of-each-continent Average Population of Each Continent | HackerRank Query the names of all continents and their respective city populations, rounded down to the nearest integer. www.hackerrank.com ❗ Answer SELECT country.continent, FLOOR(AVG(city.population)) FROM city INNER JOIN country ON city.countrycode = country.code GROUP ..
❓ Question https://www.hackerrank.com/challenges/african-cities African Cities | HackerRank Query the names of all cities on the continent 'Africa'. www.hackerrank.com ❗ Answer SELECT city.name FROM city INNER JOIN country ON city.countrycode = country.code WHERE country.continent = 'Africa'; 📌 Discussion join 후 조건에 해당하는 레코드만 추출
❓ Question https://www.hackerrank.com/challenges/asian-population Population Census | HackerRank Query the sum of the populations of all cities on the continent 'Asia'. www.hackerrank.com ❗ Answer SELECT SUM(city.population) FROM city INNER JOIN country ON city.countrycode = country.code WHERE country.continent = 'ASIA'; 📌 Discussion INNER JOIN 후 조건을 걸어서 모든 인구를 합해주었다.
❓ Question https://www.hackerrank.com/challenges/the-pads The PADS | HackerRank Query the name and abbreviated occupation for each person in OCCUPATIONS. www.hackerrank.com ❗ Answer SELECT CONCAT(name,'(',LEFT(occupation,1),')') FROM occupations ORDER BY name; SELECT CONCAT('There are a total of ' , a.cnt, ' ', LOWER(a.occupation), IF(cnt>=2,'s.','.')) FROM (SELECT occupation, COUNT(*) cnt FROM ..
❓ Question https://www.hackerrank.com/challenges/what-type-of-triangle Type of Triangle | HackerRank Query a triangle's type based on its side lengths. www.hackerrank.com ❗ Answer SELECT (CASE WHEN a>=b+c OR b>=c+a OR c>=a+b THEN 'Not A Triangle' WHEN a=b AND b=c THEN 'Equilateral' WHEN (a=b AND b!=c) OR (b=c AND c!=a) OR (c=a AND a!=b) THEN 'Isosceles' ELSE 'Scalene' END) FROM triangles; 📌 Disc..