https://leetcode.com/problems/average-selling-price/description/
Average Selling Price - LeetCode
Can you solve this real interview question? Average Selling Price - Table: Prices +---------------+---------+ | Column Name | Type | +---------------+---------+ | product_id | int | | start_date | date | | end_date | date | | price | int | +---------------
leetcode.com
1
2
3
4
5
6
7
|
# Write your MySQL query statement below
select p.product_id,round(sum(p.price*u.units)/sum(u.units),2) average_price
from Prices p
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
|
cs |
반응형
'SQL' 카테고리의 다른 글
leetcode 1327. List the Products Ordered in a Period (0) | 2023.04.08 |
---|---|
leetcode 1789. Primary Department for Each Employee (0) | 2023.04.08 |
leetcode 2356. Number of Unique Subjects Taught by Each Teacher (0) | 2023.04.06 |
leetcode 1378. Replace Employee ID With The Unique Identifier (0) | 2023.04.06 |
leetcode 1683. Invalid Tweets (0) | 2023.04.06 |
댓글