본문 바로가기

Algorithm/MySQL

(75)
[해커랭크(HackerRank)] Average Population of Each Continent (MySQL) 문제 Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. 코드 SELECT Country.Continent, FLOOR(AVG(City.population)) FROM City INNER JOIN Country ON City.CountryCode = Country.Code GROUP BY Count..
[해커랭크(HackerRank)] Population Census (MySQL) 문제 Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. 코드 SELECT SUM(City.population) FROM City INNER JOIN Country ON City.CountryCode = Country.Code WHERE Country.Continent = 'Asia' City, Country 테이블에서 모든 도시의 인구의 합계를 구하라 Continent = 'Asia' 출처
[해커랭크(HackerRank)] African Cities (MySQL) 문제 Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. 코드 SELECT City.name FROM City INNER JOIN Country ON City.CountryCode = Country.code WHERE Country.continent = 'Africa' City 테이블과 Country 테이블에서 Continent가 Africa인 모든 도시의 이름을 출력하라 출처
[LeetCode] Duplicate Emails (MySQL) 문제 코드 SELECT Email FROM person GROUP BY Email Having count(*) >= 2 /* count수 조회하기 */ SELECT Email, count(*) FROM person GROUP BY Email Person테이블에서 중복되는 이메일을 모두 찾아라 중복되는 이메일 목록을 조회하기 위해서는 group by로 묶어서 2개 이상인 이메일 주소를 조회해주면 된다 count를 먼저 조회해보면 좋을 듯! 출처