ORA-00979: not a GROUP BY expression(不是 GROUP BY 表达式)
Oracle含义
SELECT 列表中将未聚合的列与聚合函数(SUM、COUNT 等)一起使用,但该列未添加到 GROUP BY 子句中。Oracle 不知道如何对该列分组。
原因
某列在 SELECT 中但不在 GROUP BY 中;聚合函数之外的表达式未包含在 GROUP BY 列表中;HAVING 或 select 表达式不一致。
解决方法
将所有未聚合的列添加到 GROUP BY 列表:SELECT department, COUNT(*) FROM employee GROUP BY department; 或者也将该列包在聚合函数(MAX、MIN)中,或用分析函数(OVER())重新设计分组。
同一数据库的其他条目
- ORA-01400cannot insert NULL into (column)(无法将 NULL 插入(列))
- ORA-02291integrity constraint violated - parent key not found(违反完整约束条件 - 未找到父项关键字)
- ORA-02292integrity constraint violated - child record found(违反完整约束条件 - 已找到子记录)
- ORA-00918column ambiguously defined(列定义不明确)
- ORA-06550line/column PLS-... PL/SQL compilation error(行/列 PLS-... PL/SQL 编译错误)
- ORA-04068existing state of packages has been discarded(已丢弃程序包的当前状态)
- ORA-01427single-row subquery returns more than one row(单行子查询返回多个行)