-
1084. Sales Analysis III mysqlLeetCode_Study_Plan/SQL 2022. 10. 4. 11:38
https://leetcode.com/problems/sales-analysis-iii/
Sales Analysis III - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
틀린 시도
select p.product_id, p.product_name from (select product_id, sale_date from sales where sale_date between '2019-01-01' and '2019-03-31') tb join product p on p.product_id = tb.product_id where p.product_id not in (select product_id from sales where sale_date not between '2019-01-01' and '2019-03-31');
비효율적이고 4/13에서 wrong answer이 나왔음
SELECT p.product_id, p.product_name FROM Product p, Sales s WHERE p.product_id = s.product_id GROUP BY s.product_id HAVING MIN(s.sale_date) >= '2019-01-01' AND MAX(s.sale_date) <= '2019-03-31';
참고 : https://hkim-data.tistory.com/276
[LeetCode] Sales Analysis III (최소 최대 GROUP BY MINMAX 활용)
https://leetcode.com/problems/sales-analysis-iii/ 그렇게 어려운 문제는 아니지만 여러 풀이 방법이 있었다. 처음 생각한 단순한 풀이 SELECT product_id, product_name FROM Product WHERE product_id IN( SE..
hkim-data.tistory.com
테이블 두 개를 이전까지는 subquery로 만들어서 join했는데 where 절을 활용해서 깔끔하게도 풀 수 있었다.
앞으로의 SQL 문제들은 저렇게 풀어야겠다. ㅎㅎ
'LeetCode_Study_Plan > SQL' 카테고리의 다른 글
[SQL I] 마무리 (0) 2022.10.04 1587. Bank Account Summary II mysql (0) 2022.10.04 1050. Actors and Directors Who Cooperated At Least Three Times mysql (0) 2022.10.04 182. Duplicate Emails mysql (0) 2022.10.04 1158. Market Analysis I mysql (0) 2022.10.03