我有两列价格和数量。我把它们相乘了
select Price*Quantity as SubTotal from ProductInfo
现在我想将小计中所有行的总和作为总计
SUM(SubTotal) as GrandTotal
和 因此像这样的新查询
select Price*Quantity as SubTotal , SUM(SubTotal) as GrandTotal from ProductInfo
我该怎么做才能帮忙
答案 0 :(得分:0)
试试这个::
Select Price*Quantity as SubTotal,
SUM(Price*Quantity) as GrandTotal
from ProductInfo
这将按预期结果。
答案 1 :(得分:0)
Select ISNULL(Price*Quantity, 'GrandTotal') as SubTotal,
SUM(Price*Quantity) as Total
from ProductInfo
GROUP BY ISNULL(Price*Quantity, 'GrandTotal')
WITH ROLLUP