SELECT中的MAX和AVG不起作用

时间:2013-11-25 05:23:20

标签: database oracle oracle10g

我有两个分开的查询:

SELECT avg(priv_even_price) FROM private_event;

输出

"AVG(PRIV_EVEN_PRICE)"        
"387.833333333333333333333333333333333333"

SELECT max(priv_even_price) FROM private_event;

输出

"MAX(PRIV_EVEN_PRICE)"        
"950"                

如果我将这两者合并,为什么它不起作用,我在以下查询中收到错误:

SELECT max(priv_even_price) - (SELECT avg(priv_even_price) FROM private_event)
FROM private_event;

ORA-00937: not a single-group group function
00937. 00000 -  "not a single-group group function"
*Cause:    
*Action:
Error at Line: 1 Column: 39

3 个答案:

答案 0 :(得分:3)

每次都不要写SELECT,只需将函数作为表达式的一部分调用。

SELECT MAX(priv_even_price) - AVG(priv_even_price)
FROM private_event;

答案 1 :(得分:1)

SELECT
    (SELECT max(priv_even_price) FROM private_event)
  - (SELECT avg(priv_even_price) FROM private_event) AS Difference

答案 2 :(得分:0)

SELECT max(priv_even_price)-avg(priv_even_price) "Difference" FROM private_event