問(wèn)題描述
SELECT MAX(AVG(SYSDATE - inv_date)) FROM invoice;
這個(gè)查詢有什么問(wèn)題?
Avg 返回單個(gè)值 否Max 需要一個(gè)小組來(lái)處理,所以它不會(huì)執(zhí)行并給出錯(cuò)誤?請(qǐng)解釋工作這是一個(gè)不會(huì)執(zhí)行的測(cè)驗(yàn)問(wèn)題 我想知道它不執(zhí)行的原因 我不知道允許嵌套聚合函數(shù)嗎?
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 允許嵌套聚合函數(shù)(參見(jiàn) 文檔).
Oracle allows nested aggregation functions (see the documentation).
然而,它需要一個(gè)GROUP BY
.所以這是允許的:
However, it requires a GROUP BY
. So this is allowed:
SELECT MAX(AVG(SYSDATE - inv_date))
FROM invoice
GROUP BY Cust_ID;
基本上,這是一個(gè)捷徑:
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;
不過(guò),就您而言,沒(méi)有 GROUP BY
.Oracle 不允許在沒(méi)有 GROUP BY
的情況下嵌套 GROUP BY
.
In your case, though, there is no GROUP BY
. Oracle doesn't allow nested GROUP BY
without the GROUP BY
.
如果您好奇,我不喜歡這種擴(kuò)展功能.我不認(rèn)為它實(shí)際上解決了問(wèn)題.
And if you are curious, I'm not a fan of this extended functionality. I don't see that it actually solves a problem.
這篇關(guān)于嵌套聚合函數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!