[LeetCode] 1327. List the Products Ordered in a Period

Chobby·2025년 8월 8일
1

LeetCode

목록 보기
498/650

😎풀이

  1. Products 테이블과 Orders 테이블 LEFT JOIN
  2. 2020년 2월 윤년 한달간의 데이터만 조회
  3. 상품 식별자와 상품명을 기준으로 그룹화
  4. 판매량이 100건 이상인 상품을 기준으로 조회회
SELECT p.product_name, SUM(o.unit) AS unit
FROM Products AS p
LEFT JOIN Orders AS o
  ON p.product_id = o.product_id
WHERE o.order_date BETWEEN '2020-02-01' AND '2020-02-29'
GROUP BY p.product_id, p.product_name
HAVING unit >= 100;
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글