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