文件名称:分组函数的误用-SQL语言基础
文件大小:5.26MB
文件格式:PPT
更新时间:2024-05-15 13:24:59
SQL 基础
分组函数的误用 * SQL> SELECT deptno, COUNT(ename) 2 FROM emp; SELECT deptno, COUNT(ename) * ERROR at line 1: ORA-00937: not a single-group group function Deptno列没有在 GROUP BY 子句中出现 在SELECT 语句中,任何不在分组函数中出现的列,必须在 GROUP BY 子句中. * SELECT deptno, COUNT(ename) FROM emp; Illegal Queries Using Group Functions Whenever you use a mixture of individual items (DEPTNO) and group functions (COUNT) in the same SELECT statement, you must include a GROUP BY clause that specifies the individual items (in this case, DEPTNO). If the GROUP BY clause is missing, then the error message “not a single-group group function” appears and an asterisk (*) points to the offending column. You can correct the error on the slide by adding the GROUP BY clause. Any column or expression in the SELECT list that is not an aggregate function must be in the GROUP BY clause. Instructor Note Demo: l5error.sql Purpose: To illustrate executing a SELECT statement with no GROUP BY clause. SQL> SELECT deptno,COUNT(ename) 2 FROM emp 3 GROUP BY deptno; DEPTNO COUNT(ENAME) ---------- ------------ 10 3 20 5 30 6