SELECT EMP_NO IN STEAD OF SELECT*
I replaced * by emp_no since we are only interested in employees no but not in all of their information, is it right this way???
select emp_no, avg(salary) from salaries
group by emp_no
having avg(salary)>120000;
Hi Asmaa!
Yes, this is also correct. Bravo!
Hope this helps.
Best,
Tsvetelin
I receive an error when using:
SELECT
*, AVG(salary)
FROM
salaries
GROUP BY emp_no
HAVING AVG(salary) > 120000;
when I change the * for emp_no it runs fine.
Hi Sandra!
Thanks for reaching out.
Could you please share with us a screenshot of the whole error message you've encountered? This can help us assist you better. Thank you.
Looking forward to your answer.
Best,
Tsvetelin
SELECT *, AVG(salary) FROM salaries GROUP BY emp_no HAVING AVG(salary) > 120000 LIMIT 0, 1000
Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'employees.salaries.salary' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Hi Chun!
Thanks for reaching out.
Please, execute the following command:
set @@global.sql_mode := replace(@@global.sql_mode, 'ONLY_FULL_GROUP_BY', '');
Then restart your Workbench. It should fix the issue.
Hope this helps.
Best,
Tsvetelin