Last answered:

17 Nov 2022

Posted on:

15 Nov 2022

0

Numbers changed after applying the GROUP BY clause

Can someone explains why the number changed after applying the GROUP BY clause?
Before GROUP BY
image.png

After GROUP BY
image.png

3 answers ( 0 marked as helpful)
Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

16 Nov 2022

1

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.

Instructor
Posted on:

16 Nov 2022

1

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

Posted on:

17 Nov 2022

0

Thank you both for making it clear for me.

Submit an answer