rubus0304 님의 블로그
[데이터분석] 코드카타 92 본문
https://leetcode.com/problems/average-selling-price/description/
92. Average Selling Price
Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places. If a product does not have any sold units, its average selling price is assumed to be 0.
Return the result table in any order.
(오답)
select u.product_id,
avg(price) average_price
from Prices p join UnitsSold u on p.product_id = u.product_id
group by 1
select
p.product_id,
ifnull(round(sum(p.price * u.units) / sum(u.units), 2), 0)
as average_price
from
Prices as p left join UnitsSold as u on p.product_id = u.product_id
and u.purchase_date between p.start_date and p.end_date
group by 1
'Data Analyst > daily' 카테고리의 다른 글
[데이터분석] 코드카타 94 (2) | 2024.11.01 |
---|---|
[데이터분석] 코드카타 93 (0) | 2024.10.31 |
[데이터분석] 코드카타 91 (0) | 2024.10.29 |
[데이터 분석] 코드카타 90 (0) | 2024.10.28 |
[QCC 1회차] (2) | 2024.10.25 |