Hi, I have a question
this my query:
USE employees;
USE employees;
DROP PROCEDURE IF EXISTS emp_avg_salary;
DELIMITER $$
CREATE PROCEDURE emp_avg_salary(IN p_emp_no INTEGER)
BEGIN
SELECT
e.first_name,e.last_name,AVG(s.salary)
FROM
employees e
JOIN
salaries s ON e.emp_no = s.emp_no
WHERE
e.emp_no=p_emp_no;
END $$
DELIMITER ;
CALL emp_avg_salary(11300); I have received this error 0
4
15:54:05
CALL emp_avg_salary(11300)
Error Code: 1140. In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'employees.e.first_name'; this is incompatible with sql_mode=only_full_group_by
0.000 se , I have been repeatedly receiving this error recently, please help!!
Hi Marwa!
Thanks for reaching out!
When using aggregate functions you will need a GROUP BY clause in most of the cases. This is what is missing in your query. This is because you use an aggregate function without the GROUP BY clause. You can use the following code to change the Workbench settings:
set @@global.sql_mode :=
replace(@@global.sql_mode, 'ONLY_FULL_GROUP_BY', '');
Hope this helps.
Best,
Martin