DB2 SQL-Error: -122
SQLState: 42803
Short Description: A SELECT STATEMENT WITH NO GROUP BY CLAUSE CONTAINS A COLUMN NAME AND AN AGGREGATE FUNCTION IN THE SELECT CLAUSE OR A COLUMN NAME IS CONTAINED IN THE SELECT CLAUSE BUT NOT IN THE GROUP BY CLAUSE
The SELECT statement contains one of these errors: v The statement contains a column name and a aggregate function in the SELECT clause, but no GROUP BY clause. v A column name is contained in the SELECT clause (possibly within a scalar function) but not in the GROUP BY clause. Grouping expressions can be used in a SELECT list. A grouping expression specifies only one value for each group. A grouping expression that is specified in this context must exactly match a grouping expression that is specified in the GROUP BY clause, except that blanks are not significant. Attention: A HAVING clause specified without a GROUP BY clause implies a GROUP BY with no columns. Thus, no column names are allowed in the SELECT clause. v A sort-key-expression was specified in the ORDER BY clause, the result table contains grouped data, but the select-clause and ORDER BY clause contain a mixture of grouped data and non-grouped data. Grouping expressions can be used in a sort-key-expression of an ORDER BY clause. A grouping expression specifies only one value for each group. A grouping expression that is specified in this context must exactly match a grouping expression that is specified in the GROUP BY clause, except that blanks are not significant.System action: The statement cannot be executed. Programmer response: You can correct the statement by: v including the columns in the GROUP BY clause that are in the SELECT clause, or v removing the columns from the SELECT clause. Refer to Chapter 4 of DB2 SQL Reference for information about the use of GROUP BY clauses in SQL statements.