ORA-00937: not a single-group group function的解決方法

xingfei80發表於2010-07-06

轉自:http://space.itpub.net/23184238/viewspace-630395

A SELECT list cannot include both a group function, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, and an individual column expression, unless the individual column expression is included in a GROUP BY clause.

Drop either the group function or the individual column expression from the SELECT list or add a GROUP BY clause that includes all individual column expressions listed.


eg:

SQL> select inst_id,count(*) from gv$session;
select inst_id,count(*) from gv$session
*
ERROR at line 1:
ORA-00937: not a single-group group function

Because we have a group function (COUNT) in our column list, and an additional column (OWNER), we have to include the GROUP BY clause in our select statement.


SQL> select inst_id,count(*) from gv$session group by inst_id;

INST_ID COUNT(*)
---------- ----------
1 31
2 29

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14663377/viewspace-1034992/,如需轉載,請註明出處,否則將追究法律責任。

相關文章