문제
Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places.
Return the result table in any order.
The result format is in the following example.
문제 풀이
SELECT p.product_id
, IFNULL(ROUND(SUM(units*price) / SUM(units),2),0) AS average_price
FROM Prices p LEFT JOIN UnitsSold u
ON p.product_id = u.product_id
AND u.purchase_date BETWEEN start_date AND end_date
GROUP BY p.product_id
오답 이유
1. 순간적으로 JOIN을 할 때, 날짜 사이에 값을 배치하는 법을 까먹었다.
'취준 > 코팅 테스트' 카테고리의 다른 글
[LeetCode] 1978. Employees Whose Manager Left the Company (0) | 2024.04.01 |
---|---|
[LeetCode] - 1890. The Latest Login in 2020 (0) | 2024.03.29 |
[LeetCode] - 180. Consecutive Numbers (0) | 2024.03.27 |
[LeetCode] - 1527. Patients With a Condition (0) | 2024.03.26 |
[LeetCode] - 586. Customer Placing the Largest Number of Orders (0) | 2024.03.25 |