You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Both were created to filter rows of data, but they filter 2 separate things
-- Where is going to filters rows based off columns of data
-- Having is going to filter rows based off aggregated columns when grouped
SELECT gender, AVG(age)
FROM employee_demographics
GROUP BY gender
;
-- let's try to filter on the avg age using where
SELECT gender, AVG(age)
FROM employee_demographics
WHEREAVG(age) >40
GROUP BY gender
;
-- this doesn't work because of order of operations. On the backend Where comes before the group by. So you can't filter on data that hasn't been grouped yet