문제 출저https://leetcode.com/problems/article-views-i/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이상품 이름, 년도, 가격을 출력해야 합니다.위의 정보들은 두 개의 테이블에 흩어져 있으므로 조인을 통해서 원하는 정보들을 모읍니다. SQL# 상품 이름, 년도, 가격 출력# 상품 이름은 외부 테이블이므로 조인을 통해 가져온다. select p.product_name, s.year, s.price from Sales as sjoin Product as p on s.product_id = p.product_id
문제 출저https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이Employees와 EmployUNI 두 개의 테이블이 주어집니다. 유니크 아이디와 이름을 출력하는 솔루션을 만들어야 합니다.두 개의 테이블을 id로 조인하여 Employees 테이블의 id와 EmployUNI 테이블의 unique_id를 가져옵니다. SQL# 고유 ID를 표현select u.unique_id, e.namefrom Employees as e left join EmployeeUNI as u on e.id = u.id
문제 출저 문제 풀이잘못된 트윗의 ID를 찾는 솔루션을 작성해야 합니다. 잘못된 트윗 ID는 문자수가 15를 초과하는 것 입니다.where 문에서 15자를 초과하는 것을 찾습니다. SQLselect tweet_idfrom Tweets where char_length(content) > 15
문제 출저https://leetcode.com/problems/article-views-i/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이자신의 작품을 본 작가 id를 출력해야 합니다 where 사용하여 author_id와 viewer_id 같은 것을 선택합니다. 중복을 제거하기 위해 distinct를 사용합니다. order by로 id를 정렬합니다. SQLselect distinct author_id as idfrom Viewswhere author_id = viewer_idorder by id
문제 출저https://leetcode.com/problems/big-countries/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이면적이 3000000 이상 인구수가 25000000 이상인 나라의 이름, 인구, 면적을 출력해야 합니다.해당 조건에 맞게 where문을 사용합니다. 문제 풀이select name, population, area from World where area >= 3000000 or population >= 25000000
문제 출저https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이아이디가 2가 아닌 행들을 조회해야 합니다. where 절을 사용하여 2가 아닌 것을 추가합니다. 또한 null 인 것도 조회해야 하므로 is null을 사용합니다. SQLselect namefrom Customer where referee_id is null or referee_id 2 # != 랑 동일
문제 출저https://leetcode.com/problems/recyclable-and-low-fat-products/description/?envType=study-plan-v2&envId=top-sql-50 문제 풀이Products 테이블의 low_facts와 recycleable의 모두 Y인 경우의 데이털르 구해야 합니다.where 절을 사용하여 조건에 맞는 행을 가져옵니다. SQL# Write your MySQL query statement belowselect product_idfrom Productswhere low_fats = 'Y' and recyclable = 'Y'