如何将 select max 和 count 结合起来?
我得到了这个:
select ordernr
from users
having count(ordernr) =
( select max(count(ordernr))
from users where ordernr = ordernr
group by ordernr )
group by ordernr
从所有用户中获取最常用的订单号(ordernr)。
如何将其导入ABAP SAP系统?我已经尝试过这个:
select SINGLE ordernr
from ZDEVXXX_PROJECT3 INTO ordernrU
having count( * ) =
( select max( count( * ) )
from ZDEVXXX_PROJECT3
where ordernr = ordernr
group by ordernr )
但我收到此错误:
"Unknown columnname COUNT("
How to join max and count in ABAP?上面的 SQL 查询对我来说在 Oracle 中运行。 谢谢!
I've got this:
select ordernr
from users
having count(ordernr) =
( select max(count(ordernr))
from users where ordernr = ordernr
group by ordernr )
group by ordernr
to get the most used order-number (ordernr) from all users.
How to get it into ABAP SAP System? I've tried this:
select SINGLE ordernr
from ZDEVXXX_PROJECT3 INTO ordernrU
having count( * ) =
( select max( count( * ) )
from ZDEVXXX_PROJECT3
where ordernr = ordernr
group by ordernr )
But I get this error:
"Unknown columnname COUNT("
How to combine max and count in ABAP? The SQL Query above is working in Oracle for me.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果要在 HAVING 子句中使用 COUNT(*),则需要在结果集中包含 COUNT(*)。请参阅http://help.sap.com/abapdocu_751/en/ABENWHERE_LOGEXP_ALL_ANY_SOME.htm 为例。
You need to have COUNT(*) in the result set if you want to use it in the HAVING clause. See http://help.sap.com/abapdocu_751/en/ABENWHERE_LOGEXP_ALL_ANY_SOME.htm for an example.
从版本 6.1 开始,您可以在 HAVING 子句中使用聚合。
但你的答案是“不可能”。聚合只能采用
aggr( {[distinct] column | *} )
形式因此,您必须
然后以编程方式找到最大计数。并且只有在HAVING条件下才能使用它。
Since release 6.1 you can use aggregates in HAVING clause.
But your answer is "No way". Aggregates must be only in form
aggr( {[distinct] column | *} )
So you must to
Then to find maximum of counts programmaticaly. And only then to use it in HAVING condition.
或者您可以使用 ABAP Open SQL。它使您可以访问特定数据库的 SQL,并且可以执行上述查询。
Or you can use ABAP Open SQL. It gives you the access to SQL of your particular DB and you can execute your mentioned above query.