Actual Data:
| ProductId | Name | Quantity |
|---|---|---|
| 1 | Product A | 10 |
| 2 | Product B | 10 |
| 3 | Product C | 10 |
| ProductId | Name | Cal Quantity |
|---|---|---|
| 1 | Product A | 10 |
| 2 | Product B | 20 |
| 3 | Product C | 30 |
SQL Server Query:
SELECT P.ProductId, P.Name, SUM(PC.Quantity) AS Cal Quantity
FROM Products AS P LEFT OUTER JOIN Products AS PC
ON PC.ProductId <= P.ProductId
GROUP BY P.ProductId, P.Name
FROM Products AS P LEFT OUTER JOIN Products AS PC
ON PC.ProductId <= P.ProductId
GROUP BY P.ProductId, P.Name
No comments:
Post a Comment