본문 바로가기

Algorithm

(131)
[LeetCode] 181. Employees Earning More Than Their Managers (MySQL) 문제 코드 SELECT a.name as Employee FROM Employee as a /*사원 테이블*/ INNER JOIN Employee as b /*매니저 테이블*/ ON a.managerId = b.id WHERE a.salary > b.salary /* ["employee_name", "manager_name"], ["Joe", "Sam"] ["Henry", "Max"] */ employee 테이블에는 모든 직원과 매니저들의 데이터를 가지고 있다 이 사람들 중에서 매니저보다 더 많이 버는 사람을 찾아라 a.managerId와 b의 id를 조인 조건으로 주면서 a는 사원 테이블이 되고 b는 매니저 테이블로 만든다 사원의 월급이 매니저보다 많은 데이터만 출력 출처
[LeetCode] 183. Customers Who Never Order (MySQL) 문제 Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything. 코드 SELECT Customers.Name as Customers FROM Customers LEFT JOIN Orders ON Customers.Id = Orders.CustomerId WHERE orders.Id is null 아무것도 주문하지 않은 모든 고객을 찾아라 그렇다면 Customer테이블에는 데이터가 있지만 Orders테이블에는 데이터가 없을 것이다 그렇기 때문에 데이터가 있는 Customers를 기준으로 LEFT ..
[해커랭크(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' 출처