有時候查詢會遇到如下錯誤
SCOTT@PROD> select deptno,sum(sal) from emp;
select deptno,sum(sal) from emp
*
ERROR at line 1:
ORA-00937: not a single-group group function
原因:這句話不會運行,因為deptno要求每行都顯示,而sum要求統計后再顯示,違反了原則。在有組函數的select中,不是組函數的列,一定要放在group by子句中。
正確語句:select deptno,sum(sal) from emp group by deptno;