这需要在 SQL Server 2005 和 2008 中工作,而无需调整兼容性级别(如果可以的话)
Select
CASE GROUPING([Store ID]) WHEN 1 THEN '[Store ID]' ELSE [Store ID] END [Store ID],
CASE GROUPING([Cashier]) WHEN 1 THEN '[Cashier]' ELSE [Cashier] END [Cashier],
CASE GROUPING([Register]) WHEN 1 THEN '[Register]' ELSE [Register] END [Register],
sum([Amex]) AS [Amex],
sum([C.Card]) AS [C.Card],
sum([Cash]) AS [Cash],
sum([House Acct]) AS [House Acct],
sum([MasterCard]) AS [MasterCard],
sum([Str Cr]) AS [Str Cr],
sum([Visa/MC]) AS [Visa/MC]
from
#a13
group by
[Store ID],
[Cashier],
[Register]
with rollup
这返回:
我如何调整代码以不实际显示卷起的行?意思是删除最后 3 行或其中带有 [ ] 的任何内容。我需要Rollup
在 SQL 2005 中使用,所以我可以使用case grouping
.