0

我有两列价格和数量。我已经乘以它们

select Price*Quantity as SubTotal from ProductInfo 

现在我想将小计中所有行的总和作为总计

SUM(SubTotal) as GrandTotal

因此像这样的新查询

select Price*Quantity as SubTotal , SUM(SubTotal) as GrandTotal from ProductInfo 

我该怎么做请帮忙

4

2 回答 2

0
Select ISNULL(Price*Quantity, 'GrandTotal') as SubTotal, 
SUM(Price*Quantity) as Total 
from ProductInfo
GROUP BY   ISNULL(Price*Quantity, 'GrandTotal')
WITH ROLLUP
于 2013-09-29T10:13:34.353 回答
0

试试这个::

Select Price*Quantity as SubTotal, 
SUM(Price*Quantity) as GrandTotal 
from ProductInfo 

这将按预期结果。

于 2013-09-29T07:13:19.440 回答