[LeetCode/SQL] 1251. Average Selling Price

Sooyeon·2023년 11월 13일
0

문제풀이 

목록 보기
42/95
post-thumbnail

[LeetCode/SQL]


📌 1251. Average Selling Price

문제

풀이

- 각 상품별 평균 가격을 출력하라.
=>소수점2자리까지 출력

방법

SELECT p.product_id, IFNULL(round(SUM(p.price*u.units)/sum(u.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 p.Start_date and p.end_date
GROUP BY p.product_id

0개의 댓글