문제
입력 코드
1.
SELECT
p.product_id,
ROUND(SUM(units * price) / SUM(units), 2) AS average_price
FROM Prices AS p
JOIN UnitsSold AS u
ON (p.product_id = u.product_id)
AND (u.purchase_date BETWEEN start_date AND end_date)
GROUP BY product_id
2.
SELECT
p.product_id,
ROUND(SUM(units * price) / SUM(units), 2) AS average_price
FROM Prices AS p
INNER JOIN UnitsSold AS u
ON (p.product_id = u.product_id)
WHERE u.purchase_date BETWEEN start_date AND end_date
GROUP BY product_id
코드 설명
#SELECT # ROUND #SUM #JOIN #INNER JOIN #BETWEEN #GROUP BY
문제 출처
'SQL' 카테고리의 다른 글
#92. [LeetCode / MySQL] 1633. Percentage of Users Attended a Contest (0) | 2023.09.18 |
---|---|
#91. [LeetCode / MySQL] 1075. Project Employees I (0) | 2023.09.17 |
#89. [LeetCode / MySQL] 620. Not Boring Movies (0) | 2023.09.15 |
#88. [LeetCode / MySQL] 1934. Confirmation Rate (0) | 2023.09.14 |
#87. [LeetCode / MySQL] 570. Managers with at Least 5 Direct Reports (0) | 2023.09.13 |