본문 바로가기

Algorithm

(131)
[해커랭크(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를 먼저 조회해보면 좋을 듯! 출처
[LeetCode] 620. Not Boring Movies (MySQL) 문제 cinema 테이블의 id가 홀수이고, description이 지루하지 않은 값만 출력 순서는 rating이 내림차순으로, 그러니까 점수가 가장 높은 순으로 출력 코드 SELECT * FROM Cinema WHERE id % 2 = 1 -- 홀수 아이디만 출력 -- wHERE MOD(id, 2) = 1 -- 홀수 아이디 AND description "boring" -- 지루하지 않은 description만 출력 ORDER BY rating DESC -- 점수가 가장 높은 순으로 출력 홀수 아이디만 출력하는 조건은 id에서 2를 나눴을 때 나머지가 1일 경우 홀수이기 때문에 where절에 해당 조건 추가 지루하지 않은 description만 출력하기 위한 조건 추가 점수가 가장 높은 순으로 출력하기 ..
[LeetCode] 595. Big Countries (MySQL) 문제 코드 Select name, population, area From World Where area > 3000000 OR population > 25000000 면적이 300만 km 초과이거나 인구가 2500백만 (25*100만) 초과인 나라 구하기 Name, population, area 출력 출처