Skip to content

Commit

Permalink
Create code.md
Browse files Browse the repository at this point in the history
  • Loading branch information
datahubber authored Aug 9, 2023
1 parent e4836bf commit 73e6c17
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SQL/Aggregate/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT
u.product_id,
ROUND(SUM(p.price * u.units) / SUM(u.units), 2) AS average_price
FROM unitssold u
JOIN prices p ON 1=1
AND p.product_id = u.product_id
AND u.purchase_date BETWEEN p.start_date AND p.end_date
GROUP BY u.product_id;

0 comments on commit 73e6c17

Please sign in to comment.