Skip to content

Commit 73e7049

Browse files
authored
feat: add sql solution to lc problem: No.1251 (#749)
No.1251. Average Selling Price
1 parent a047457 commit 73e7049

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

solution/1200-1299/1251.Average Selling Price/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ Result table:
8383
### **SQL**
8484

8585
```sql
86-
86+
SELECT p.product_id,
87+
Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2)
88+
average_price
89+
FROM Prices p
90+
INNER JOIN UnitsSold u
91+
ON p.product_id = u.product_id
92+
WHERE u.purchase_date BETWEEN p.start_date AND p.end_date
93+
GROUP BY p.product_id;
8794
```
8895

8996
<!-- tabs:end -->

solution/1200-1299/1251.Average Selling Price/README_EN.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96
8787
### **SQL**
8888

8989
```sql
90-
90+
SELECT p.product_id,
91+
Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2)
92+
average_price
93+
FROM Prices p
94+
INNER JOIN UnitsSold u
95+
ON p.product_id = u.product_id
96+
WHERE u.purchase_date BETWEEN p.start_date AND p.end_date
97+
GROUP BY p.product_id;
9198
```
9299

93100
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SELECT p.product_id,
2+
Round(( Sum(u.units * p.price) + 0.0 ) / ( Sum(units) + 0.0 ), 2)
3+
average_price
4+
FROM Prices p
5+
INNER JOIN UnitsSold u
6+
ON p.product_id = u.product_id
7+
WHERE u.purchase_date BETWEEN p.start_date AND p.end_date
8+
GROUP BY p.product_id;

0 commit comments

Comments
 (0)