From a20af2ba5845a0a3217df9c02706485b3c9eae32 Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Sun, 13 Mar 2022 22:46:43 +0530 Subject: [PATCH 1/6] Added Solution file --- .../1200-1299/1251.Average Selling Price/Solution.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 solution/1200-1299/1251.Average Selling Price/Solution.sql diff --git a/solution/1200-1299/1251.Average Selling Price/Solution.sql b/solution/1200-1299/1251.Average Selling Price/Solution.sql new file mode 100644 index 0000000000000..263f649b9f5b4 --- /dev/null +++ b/solution/1200-1299/1251.Average Selling Price/Solution.sql @@ -0,0 +1,8 @@ +SELECT p.product_id, + Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) + avg_price +FROM Prices p + INNER JOIN UnitsSold u + ON p.product_id = u.product_id +WHERE u.purchase_date BETWEEN p.start_date AND p.end_date +GROUP BY p.product_id; From 97467ec0940a7ee1dea32dab34201e894278916f Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Sun, 13 Mar 2022 22:47:48 +0530 Subject: [PATCH 2/6] updated readme --- solution/1200-1299/1251.Average Selling Price/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/solution/1200-1299/1251.Average Selling Price/README.md b/solution/1200-1299/1251.Average Selling Price/README.md index 01da77b705cf9..4040e6569e494 100644 --- a/solution/1200-1299/1251.Average Selling Price/README.md +++ b/solution/1200-1299/1251.Average Selling Price/README.md @@ -83,7 +83,14 @@ Result table: ### **SQL** ```sql - +SELECT p.product_id, + Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) + avg_price +FROM Prices p + INNER JOIN UnitsSold u + ON p.product_id = u.product_id +WHERE u.purchase_date BETWEEN p.start_date AND p.end_date +GROUP BY p.product_id; ``` From 05e8449ed8672144840bda0f9dc76ee28674c463 Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Sun, 13 Mar 2022 22:48:51 +0530 Subject: [PATCH 3/6] updated readme_en --- .../1200-1299/1251.Average Selling Price/README_EN.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/solution/1200-1299/1251.Average Selling Price/README_EN.md b/solution/1200-1299/1251.Average Selling Price/README_EN.md index c419fa7c33666..6f83cf14cf86a 100644 --- a/solution/1200-1299/1251.Average Selling Price/README_EN.md +++ b/solution/1200-1299/1251.Average Selling Price/README_EN.md @@ -87,7 +87,14 @@ Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96 ### **SQL** ```sql - +SELECT p.product_id, + Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) + avg_price +FROM Prices p + INNER JOIN UnitsSold u + ON p.product_id = u.product_id +WHERE u.purchase_date BETWEEN p.start_date AND p.end_date +GROUP BY p.product_id; ``` From e380c7dd9578feef6afabd7502183d2f9c88a5e4 Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Mon, 14 Mar 2022 08:46:13 +0530 Subject: [PATCH 4/6] Update Solution.sql --- solution/1200-1299/1251.Average Selling Price/Solution.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/1200-1299/1251.Average Selling Price/Solution.sql b/solution/1200-1299/1251.Average Selling Price/Solution.sql index 263f649b9f5b4..dda9eb5474f51 100644 --- a/solution/1200-1299/1251.Average Selling Price/Solution.sql +++ b/solution/1200-1299/1251.Average Selling Price/Solution.sql @@ -1,6 +1,6 @@ SELECT p.product_id, Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) - avg_price + average_price FROM Prices p INNER JOIN UnitsSold u ON p.product_id = u.product_id From 2e424a6be1dc430b118247886b75a9f23fe43887 Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Mon, 14 Mar 2022 08:46:35 +0530 Subject: [PATCH 5/6] Update README.md --- solution/1200-1299/1251.Average Selling Price/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/1200-1299/1251.Average Selling Price/README.md b/solution/1200-1299/1251.Average Selling Price/README.md index 4040e6569e494..58915e7761c37 100644 --- a/solution/1200-1299/1251.Average Selling Price/README.md +++ b/solution/1200-1299/1251.Average Selling Price/README.md @@ -85,7 +85,7 @@ Result table: ```sql SELECT p.product_id, Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) - avg_price + average_price FROM Prices p INNER JOIN UnitsSold u ON p.product_id = u.product_id From 19877adb2c3ad3204d6b10ff486704b5461d7332 Mon Sep 17 00:00:00 2001 From: Aldrin Marz7! <53973174+Dhoni77@users.noreply.github.com> Date: Mon, 14 Mar 2022 08:46:52 +0530 Subject: [PATCH 6/6] Update README_EN.md --- solution/1200-1299/1251.Average Selling Price/README_EN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/1200-1299/1251.Average Selling Price/README_EN.md b/solution/1200-1299/1251.Average Selling Price/README_EN.md index 6f83cf14cf86a..06eb6495c638d 100644 --- a/solution/1200-1299/1251.Average Selling Price/README_EN.md +++ b/solution/1200-1299/1251.Average Selling Price/README_EN.md @@ -89,7 +89,7 @@ Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96 ```sql SELECT p.product_id, Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2) - avg_price + average_price FROM Prices p INNER JOIN UnitsSold u ON p.product_id = u.product_id