LeetCode - 1327. List the Products Ordered in a Period (MySQL)

조민수·2024년 6월 12일
0

LeetCode

목록 보기
32/61

Easy, SQL - GROUP BY, HAVING

RunTime : 1372 ms


문제

Write a solution to get the names of products that have at least 100 units ordered in February 2020 and their amount.

Return the result table in any order.

The result format is in the following example.


풀이

  • 자꾸 HAVING절의 내용을 WHERE절에 올리는 실수를 반복한다.
  • 다시 이론을 정립해야겠음
  • 문제는 어렵지 않았음 프로그래머스 Lv2 ~ Lv3 사이
SELECT P.product_name, SUM(O.unit) as unit
FROM Products as P JOIN Orders as O ON P.product_id = O.product_id
WHERE O.order_date LIKE '2020-02%'
GROUP BY 1
HAVING SUM(O.unit) >= 100
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글