문제
입력 코드
1.
SELECT p.product_name, SUM(o.unit) AS unit
FROM Products AS p
JOIN Orders AS o
USING(product_id)
WHERE o.order_date BETWEEN '2020-02-01' AND '2020-02-29'
GROUP BY p.product_id, p.product_name
HAVING SUM(o.unit) >= 100
2.
SELECT p.product_name, SUM(o.unit) AS unit
FROM Products AS p
JOIN Orders AS o
USING(product_id)
WHERE MONTH(o.order_date) = 2 AND YEAR(order_date) = 2020
GROUP BY o.product_id
HAVING unit >= 100
코드 설명
#SELECT #SUM #JOIN #USING #WHERE #BETWEEN #GROUP BY #HAVING #MONTH #YEAR
문제 출처
'SQL' 카테고리의 다른 글
#124. [LeetCode / MySQL] 1517. Find Users With Valid E-Mails (0) | 2024.06.23 |
---|---|
#122. [LeetCode / MySQL] 1484. Group Sold Products By The Date (0) | 2024.06.22 |
#121. [LeetCode / MySQL] 176. Second Highest Salary (0) | 2024.06.22 |
#120. [LeetCode / MySQL] 196. Delete Duplicate Emails (0) | 2024.06.21 |
#119. [LeetCode / MySQL] 1527. Patients With a Condition (0) | 2024.06.21 |