問題描述
SELECT MAX(AVG(SYSDATE - inv_date)) FROM invoice;
這個查詢有什么問題?
Avg 返回單個值 否Max 需要一個小組來處理,所以它不會執行并給出錯誤?請解釋工作這是一個不會執行的測驗問題 我想知道它不執行的原因 我不知道允許嵌套聚合函數嗎?
Avg returns single value no Max requires a group to work on so it dosent execute and give error? Please explain working It's a quiz question according to which it won't execute I want to know the reason why it dosent execute I can't figure it out nested aggregate functions are allowed right?
推薦答案
Oracle 允許嵌套聚合函數(參見 文檔).
Oracle allows nested aggregation functions (see the documentation).
然而,它需要一個GROUP BY
.所以這是允許的:
However, it requires a GROUP BY
. So this is allowed:
SELECT MAX(AVG(SYSDATE - inv_date))
FROM invoice
GROUP BY Cust_ID;
基本上,這是一個捷徑:
Basically, this is a short-cut for:
SELECT MAX(x)
FROM (SELECT AVG(SYSDATE - inv_date) as x
FROM invoice
GROUP BY Cust_Id
) i;
不過,就您而言,沒有 GROUP BY
.Oracle 不允許在沒有 GROUP BY
的情況下嵌套 GROUP BY
.
In your case, though, there is no GROUP BY
. Oracle doesn't allow nested GROUP BY
without the GROUP BY
.
如果您好奇,我不喜歡這種擴展功能.我不認為它實際上解決了問題.
And if you are curious, I'm not a fan of this extended functionality. I don't see that it actually solves a problem.
這篇關于嵌套聚合函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!