Last answered:

13 Mar 2023

Posted on:

12 Mar 2023

0

excercise question

Why we obtained 101 rows from 'from salaries' and 807 from 'from employees.salaries'. Whats the difference? Also, in the same example why's that we can write "WHERE salary > 120000" to obtain 807 rows result but ony 11 rows for "HAVING salary > 120000" ?  Thanks. 

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

13 Mar 2023

0

Hi Angela!
Thanks for reaching out.


These two queries were provided for discussion, to emphasize the difference between using WHERE and HAVING. 

When using WHERE instead of HAVING, the output is larger because in the output we include individual contracts higher than $120,000 per year. The output does not contain average salary values.

In other words, you take all rows for which the salary is higher than $120,000 per year, and then you take the average of each single row. Of course, this produces the same value.


Hope this helps.
Best,
Tsvetelin

Submit an answer