Numbers changed after applying the GROUP BY clause
Can someone explains why the number changed after applying the GROUP BY clause?
Before GROUP BY
After GROUP BY
Good evening Maged Kamal,
Answer is given in the video lesson from 1:55 onwards but I had to listen a couple of times and review the data to interpret the 'actual' meaning.
66924.2706 is the AVERAGE of ALL of the Salaries for ALL Departments for ALL Employees.
And because we have not used the GROUP BY option it has applied this value against the FIRST Department Name (this is the MySQL 'default' as stated in the video). So if there was not a Customer Service department, it would have given this figure against the 'first' alphabetically sorted department from the list - Development.
Once we use the GROUP BY, the 'true\correct' values are applied to each department name - giving 54959.6724 to Customer Service.
Hope this makes sense.
Regards,
Kev T.
Hi Maged and Kev!
Thanks for reaching out.
@: Kev
Thanks for sharing this piece of information with the Community!
@: Maged
Kev said it all. Because we have not used the GROUP BY clause it has applied this value against the first met department name. So, we need to use this clause.
Hope this helps.
Best,
Tsvetelin
Thank you both for making it clear for me.