[英]Oracle - Not a single-group group function
For the following sql command 对于以下sql命令
select h.hacker_id
,h.name
,challenges_created
from hackers h
inner join (
select hacker_id
,count(*) as challenges_created /* line 1 */
from challenges
group by hacker_id
order by 2 desc
) tmp on h.hacker_id = tmp.hacker_id
order by challenges_created desc
,h.hacker_id;
so far so good but 到目前为止很好,但是
As soon as I try to add max(count(*)) as maximum
to the line 1 it give error as: 一旦我尝试将
max(count(*)) as maximum
到第1行,它就会给出如下错误:
Not a single-group group function
不是单组分组功能
This is the code for which it gives error : 这是它给出错误的代码:
select h.hacker_id
,h.name
,challenges_created
from hackers h
inner join (
select hacker_id
,count(*) as challenges_created
,max(count(*)) as maximum
from challenges
group by hacker_id
) tmp on h.hacker_id = tmp.hacker_id
order by challenges_created desc
,h.hacker_id;
I am basically interested in getting the maximum count ie maximum number of challenges created
so far. 我基本上对获得最大数量感兴趣,即到目前为止
challenges created
最大challenges created
数量。
I am new to sql, kindly help and oblige. 我是sql新手,请帮忙。 Thanks in advance.
提前致谢。 And yes, of course!
是的,当然! I know many such question have been asked in recent past but none matches my situation which is why I am asking it again.
我知道最近已经问过许多这样的问题,但是没有一个与我的情况相符,这就是为什么我再次问这个问题。
Try this: 尝试这个:
with x as (
select h.hacker_id, h.name, count(*) challenges_created
from hackers h
inner join challenges on h.hacker_id = challenges.hacker_id
group by h.hacker_id, h.name
)
select x.*,
(select max(challenges_created) from x) as "max"
from x
order by challenges_created desc, hacker_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.