开发者

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,

Roll up and Cube operator in access (Summary Queries)

But the expected result is this:

Roll up and Cube operator in access (Summary Queries)


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜