SELECT [Type], [Total Sales] From Before
union all
SELECT 'Total', Sum([Total Sales]) From Before
如果你在订购方面有问题,就像 一建议的那样,试试这个:
select [Type], [Total Sales]
from (SELECT [Type], [Total Sales], 0 [Key]
From Before
union all
SELECT 'Total', Sum([Total Sales]), 1 From Before) sq
order by [Key], Type
SELECT CASE
WHEN (GROUPING([Type]) = 1) THEN 'Total'
ELSE [Type] END AS [TYPE]
,SUM([Total Sales]) as Total_Sales
From Before
GROUP BY
[Type] WITH ROLLUP
SELECT
Type = ISNULL(Type, 'Total'),
SomeIntColumn = ISNULL(SomeIntColumn, 0),
TotalSales = SUM(TotalSales)
FROM atable
GROUP BY GROUPING SETS ((Type, SomeIntColumn ), ())
ORDER BY SomeIntColumn --Displays summary row as the first row in query result