SELECT list is not in GROUP BY clause and contains nonaggregated column
时间: 2023-09-28 08:07:55 浏览: 161
This error message typically occurs in SQL queries when an aggregate function (such as SUM, COUNT, AVG) is used in conjunction with a SELECT statement that includes columns that are not included in the GROUP BY clause and are not being aggregated.
To resolve this error, you will need to either remove the nonaggregated columns from the SELECT statement or include them in the GROUP BY clause. For example, if you have a query like this:
```
SELECT department, SUM(salary), employee_name
FROM employees
GROUP BY department;
```
You would need to modify it to either remove the employee_name column:
```
SELECT department, SUM(salary)
FROM employees
GROUP BY department;
```
Or include it in the GROUP BY clause:
```
SELECT department, SUM(salary), employee_name
FROM employees
GROUP BY department, employee_name;
```
阅读全文