访问中的汇总和多维数据集运算符(汇总查询)

发布于 2024-11-30 19:42:09 字数 368 浏览 0 评论 0原文

Access 中是否有与 Rollup 和 Cube 运算符等效的操作?如果没有,如何在 Access 中编写小计和总计(汇总数据)查询?

我已经写过:

SELECT a,b FROM dumy
UNION ALL select a,sum(b) from dumy
group by a ;

输出如下图所示,或类似的内容,

在此处输入图像描述

但预期结果是这样的:

在此处输入图像描述

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, or something similar to that,

enter image description here

But the expected result is this:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日裸衫吸 2024-12-07 19:42:09

您可以使用交叉表查询。这将产生一行:

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;

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;
我的影子我的梦 2024-12-07 19:42:09

只需要排序即可。

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文