Last answered:

03 Nov 2023

Posted on:

27 Oct 2023

1

Resolved: Error code keeps popping up

SELECT 
    d.dept_name, AVG(salary)
FROM
    departments d
        JOIN
    dept_manager m ON d.dept_no = m.dept_no
        JOIN
    salaries s ON m.emp_no = s.emp_no
    ;


This is the code I put in, but I keep getting an error code about aggregate functions 


Error Code: 1140. In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'employees.d.dept_name'; this is incompatible with sql_mode=only_full_group_by


2 answers ( 1 marked as helpful)
Instructor
Posted on:

27 Oct 2023

0

Hello,

The error you're seeing is related to the ONLY_FULL_GROUP_BY SQL mode in MySQL. When this mode is enabled, any column in the SELECT clause that isn't used in an aggregate function needs to be included in the GROUP BY clause.


In your query, you're trying to get the average salary (AVG(salary)) for each department (d.dept_name). Therefore, you need to group your results by department.


Please let me know if this makes sense.

Best,

Ned

Posted on:

03 Nov 2023

0

Hello, thanks for the insight. 

I was able to group by department without any error 

Submit an answer