Skip to content

Instantly share code, notes, and snippets.

@AashishNandakumar
Created September 1, 2024 08:10
Show Gist options
  • Save AashishNandakumar/7d644507570ba52e6ae5fdb8bbf4970b to your computer and use it in GitHub Desktop.
Save AashishNandakumar/7d644507570ba52e6ae5fdb8bbf4970b to your computer and use it in GitHub Desktop.
September 1st 2024 Questions
# Write your MySQL query statement below
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment