如何在“选择”或“按查询分组”中模拟小计? [英] How to simulate the subtotal in Select or group by query ?

查看:87
本文介绍了如何在“选择”或“按查询分组”中模拟小计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟数据透视表。

如何将父字段的小计相加,就像这样


ID - SubID - SumOfSubID - TotalbyID

1 --- A ------- 11 ------------------------ 95
1 --- B ------- 13 ------------------------ 95

1 --- C ------- 71 ------------------------ 95

2 - - T ------- 33 ------------------------ 55

2 --- H - ----- 22 ------------------------ 55


如何计算这样的TotalbyID (例如:ID = 1,然后TotalByID = 11 + 13 + 71)?

目前我正在使用堆叠查询,但是如何更快地使用子查询或任何方法?

I want to simulate the pivot table.
how to sum the subtotal of the father field, like this

ID - SubID - SumOfSubID -- TotalbyID
1 --- A ------- 11 ------------------------ 95
1 --- B ------- 13 ------------------------ 95
1 --- C ------- 71 ------------------------ 95
2 --- T ------- 33 ------------------------ 55
2 --- H ------- 22 ------------------------ 55

how to calculate the TotalbyID like this (ex: ID = 1 then TotalByID = 11+13+71) ?
At the moment I''m using stacked query, but how can I do this with subquery or any method faster ?

推荐答案

这是我第一次听到堆叠查询这个短语。这是什么?


模拟小计的一个选项是在按小计类别分组的聚合查询中联合。
This is the first time I''ve heard the phrase stacked query. What is that?

One option to emulate subtotals is to union in an aggregate query that groups by your subtotal category.


在我看来您可以使用链接查询,也可以使用域聚合函数,例如 DSum()。无论如何,我希望你拥有的已经是两者中的更快。
It seems to me that you can either use linked queries, as you are, or Domain Aggregate functions such as DSum(). I expect what you have is already the faster of the two anyway.


Rabbit:

这是我第一次听到堆叠查询这个短语。那是什么?
Rabbit:
This is the first time I''ve heard the phrase stacked query. What is that?



我假设OP指的是链接到公共字段上主数据源的聚合子查询(在本例中只是[ID])。

I assumed the OP was referring to an aggregated subquery linked to the main data source on the common fields (In this case just [ID]).


这篇关于如何在“选择”或“按查询分组”中模拟小计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆