Calculate the average selling price for each product considering price changes over time.
Data Provided:
Prices Table:
Columns:
product_id (int): Unique identifier for a product.
start_date (date): Start date of a specific price period for the product.
end_date (date): End date of the specific price period for the product. (No overlapping periods for the same product exist)
price (int): Price of the product during the specified period.
UnitsSold Table:
Columns:
product_id (int): Unique identifier for a product.
purchase_date (date): Date a specific product unit was sold.
units (int): Number of units sold on the purchase date.
Desired Output:
A table named average_price with the following columns:
product_id (int): Unique identifier for a product (same as input tables).
average_price (float): Average selling price for the product, rounded to 2 decimal places.
Explanation:
Average selling price for a product is calculated by dividing the total revenue generated from the product by the number of units sold.
Consider price changes over time by using the price applicable on the purchase date for each unit sold.
SQL MySQL JOIN USING SUM ROUND DATE BETWEEN leetcode problem and solution
Watch video Average Selling Price using join sum round functions date between SQL MySQL leetcode solution online, duration hours minute second in high quality that is uploaded to the channel CodeWis Technologies by Nuhman Paramban 05 May 2024. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 6 times and liked it 0 visitors.