I have to aggregate in my query SUM of AMUNT
field according to WERKS
, DATUM
and UZEIT
I try to make a group by without any success I have an error like that:
我必须根据WERKS, DATUM和UZEIT,来汇总我的查询总和,我试着让一个组没有任何成功,我有一个这样的错误:
What is the problem in my code?
我的代码有什么问题?
That is my ABAP code:
这是我的ABAP代码:
DATA: gt_compr TYPE TABLE OF yrt_h_sales
SELECT werks, extnb, datum, uzeit, sumvt, deprt, dpext, SUM( amunt ) AS amunt
INTO CORRESPONDING FIELDS OF TABLE @gt_compr
FROM yrt_h_sales
WHERE werks IN @so_werks
AND datum IN @so_datum
GROUP BY werks, datum, uzeit.
After I corrected it and I did this, the code looks as follows:
更正后,代码如下:
SELECT werks, datum, uzeit, extnb, deprt, dpext, SUM( amunt ) AS amunt
INTO CORRESPONDING FIELDS OF TABLE @gt_compr
FROM yrt_h_sales
WHERE werks IN @so_werks
AND datum IN @so_datum
GROUP BY werks, datum, uzeit, extnb, deprt, dpext.
So I don't have the compilation error anymore but the aggregation is still not working! I have a 43 line result without sum on the AMUNT
column
所以我不再有编译错误,但是聚合仍然不能工作!我有一个43行结果,没有在表列上的和
P.S. this is the structure of my table:
附注:这是我桌子的结构:
1 个解决方案
#1
6
Your observation is consistent with the documentation (and what I have so far seen in any other RDBMS I've worked with):
您的观察与文档一致(以及到目前为止我在任何其他RDBMS中看到的):
If aggregate expressions are used, any column identifiers that are not included as arguments of an aggregate function must be included after the addition
GROUP BY
.如果使用聚合表达式,则必须在加法组BY之后包含任何不作为聚合函数参数的列标识符。
Take for example the time field UZEIT
: You can tell the system to aggregate (in your case, sum up) all amounts for the same point in time by adding it to the GROUP BY
clause, or you can apply an aggregate function as well (SUM
would not make any sense here, but MIN
might), or you could omit the field altogether. You can not leave it dangling around without further specification - the field either needs to be part of the new key set created by GROUP BY
or has to have an aggregate function applied to it so that the system knows what to do with multiple datasets that might occur in the group.
比如时间字段UZEIT:你可以告诉系统聚合(在你的案例中,总结)所有金额相同的时间点通过添加GROUP by子句,或者你可以申请一个聚合函数(和没有任何意义,但是最小可能),或者你可以完全省略字段。你不能把它悬挂在没有进一步规范——这个领域需要创建新的密钥集的一部分由集团或有一个聚合函数应用于它,这样系统知道如何处理可能出现的多个数据集。
(This is basic SQL btw and not ABAP-specific knowledge.)
(顺便说一句,这是基本的SQL知识,而不是特定于abap的知识。)
#1
6
Your observation is consistent with the documentation (and what I have so far seen in any other RDBMS I've worked with):
您的观察与文档一致(以及到目前为止我在任何其他RDBMS中看到的):
If aggregate expressions are used, any column identifiers that are not included as arguments of an aggregate function must be included after the addition
GROUP BY
.如果使用聚合表达式,则必须在加法组BY之后包含任何不作为聚合函数参数的列标识符。
Take for example the time field UZEIT
: You can tell the system to aggregate (in your case, sum up) all amounts for the same point in time by adding it to the GROUP BY
clause, or you can apply an aggregate function as well (SUM
would not make any sense here, but MIN
might), or you could omit the field altogether. You can not leave it dangling around without further specification - the field either needs to be part of the new key set created by GROUP BY
or has to have an aggregate function applied to it so that the system knows what to do with multiple datasets that might occur in the group.
比如时间字段UZEIT:你可以告诉系统聚合(在你的案例中,总结)所有金额相同的时间点通过添加GROUP by子句,或者你可以申请一个聚合函数(和没有任何意义,但是最小可能),或者你可以完全省略字段。你不能把它悬挂在没有进一步规范——这个领域需要创建新的密钥集的一部分由集团或有一个聚合函数应用于它,这样系统知道如何处理可能出现的多个数据集。
(This is basic SQL btw and not ABAP-specific knowledge.)
(顺便说一句,这是基本的SQL知识,而不是特定于abap的知识。)