Access中的Rollup和Cube运算符是否有任何等价物?如果没有,我如何在Access中编写小计和总计(摘要数据)查询?
我写道:
SELECT a,b FROM dumy
UNION ALL select a,sum(b) from dumy
group by a ;
输出类似于下图,或类似的内容,
但预期结果如下:
答案 0 :(得分:0)
您可以使用Crosstab次查询。这将产生一行:
TRANSFORM Count(b.ID) AS [Count]
SELECT "BASE" AS SomeName, Count(b.ID) AS Total
FROM ATable AS b
WHERE Something='Text'
GROUP BY "BASE"
PIVOT AFieldName;
答案 1 :(得分:0)
只需要排序。
Select T.Total
, T.a
, T.b
From (
SELECT '' as Label
, a
,b
FROM dumy
UNION ALL
select 'Total' as Label
, a
,sum(b)
from dumy
group by a
) as T
Order By T.a, T.Total;