Roll up and Cube operator in access (Summary Queries)
Are there any equivalents to the Rollup and Cube operators in Access? If not, how can I write subtotal and grand total (summary data) queries in Access?
I have written :
SELECT a,b FROM dumy
UNION ALL select a,sum(b) from dumy
group by a ;
The output is like the image below开发者_StackOverflow社区, or something similar to that,
But the expected result is this:
You can use Crosstab queries. This will produce one row:
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;
It just requires sorting.
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;
精彩评论