g1201_1300.s1251_average_selling_price.script.sql Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
# Write your MySQL query statement below
# #Easy #Database #2023_06_10_Time_1371_ms_(76.11%)_Space_0B_(100.00%)
SELECT p.product_id,
ROUND(SUM(p.price * u.units) / SUM(u.units), 2) AS average_price
FROM
Prices AS p
NATURAL JOIN
UnitsSold AS u
WHERE
u.purchase_date BETWEEN p.start_date AND p.end_date
GROUP BY p.product_id;