As little as I use HAVING since once you start using CTE's an Temp Tables you can just always filter on the WHERE, this is one of the most common questions that's always asked in SQL job interviews especially if there is some sort of technical test.
In India, questions revolving around WHERE, GROUP BY and HAVING are sort of standard in technical rounds. Difference between WHERE and HAVING is guaranteed to be asked.
I feel like this was a bit rushed and could benefit from a little more explanation on the difference between HAVING and WHERE, especially since it seems to be a commonly asked technical interview question.
So i wrote one with the sakila schema using address table. Somebody please let me know if this was a correct use of Having: #shows districts that have more that 5 people(or addresses) saved: Select district, count(address_id) From sakila.address Group by district Having count(address_id) > 5 #used address_id as it's unique and entries cannot be null for a row Also aggregate functions include avg, max, min count right? Did i miss anything??
Hi, I'm trying to transition to data analytics from engineering. Apparent obstacle is that i don't have experience in data. I know that I should learn SQL. Is there any certificate that I can do to proove i'm proficient wioth SQL to future employeers? Thanks
I am following along but not actually learning, because I'm finding myself just typing what you're typing and I'm not fully thinking through what you're actually doing...
Same! But what I found helpful is that you can watch the video first and take little notes about what clauses he's using in the vid, etc. then you can open MySQL and try to redo what he did without looking at the video. This worked for me so I hope it helps :D
Alex or anybody here, I need help! Anybody have issues with their sQL management server studio 19 not automatically populating the server name and password in order to connect with the server? Am I missing something here? Can’t get started with Alex’s boot camp until I figure this out. Thank you for any input. It will be greatly appreciated! Maybe it is my computer?
Interestingly, THIS select gender, avg(age) from parks_and_recreation.employee_demographics where age > 40 group by gender ; gives: Female 45.0000 Male 52.0000
SELECT gender, AVG(age) FROM parks_and_recreation.employee_demographics GROUP BY gender HAVING AVG(age) > 40 ; VS SELECT gender, AVG(age) FROM parks_and_recreation.employee_demographics WHERE age > 40 GROUP BY gender; Key Differences: When Filtering Happens: WHERE clause: Filters individual rows before grouping. Only rows that meet the condition (age > 40) are included in the calculations. HAVING clause: Filters after grouping. The query groups all the data first, calculates the averages, and then filters the grouped results based on those averages. Impact on Results: WHERE: This query only considers employees older than 40 when calculating the average age. Both genders appear because their filtered average age is over 40. HAVING: This query calculates the average age for all employees first, then filters based on the result. In the example, only the male group’s average age is greater than 40, so only males appear in the result.
Not sure if I am correct but that's because where is using just the age column and not the some aggregate function as the parameter. From what I understood aggregate functions run only after the Group by statement so just the where age >40 should be fine.
As little as I use HAVING since once you start using CTE's an Temp Tables you can just always filter on the WHERE, this is one of the most common questions that's always asked in SQL job interviews especially if there is some sort of technical test.
In India, questions revolving around WHERE, GROUP BY and HAVING are sort of standard in technical rounds. Difference between WHERE and HAVING is guaranteed to be asked.
Short & concise. Just the relevant info. Thank you for working within my attention span!
Awesome - as usual! Straight to the point. Thanks, Alex!
I feel like this was a bit rushed and could benefit from a little more explanation on the difference between HAVING and WHERE, especially since it seems to be a commonly asked technical interview question.
In what I read, HAVING is used because it can use aggregate functions, wherein WHERE cannot. Hope it helps!
That's exactly the answer . HAVING is used with aggregate functions and with GROUP BY.
Thanks for your videos. They're really helping me.
Such a great teacher Alex! The way you are able to simplify everything into layman's terms is brilliant. Enjoying these tutorials ❤
wow wish i had you as a teacher at uni!
thank you for this bootcamp, very helpful
good to come here!!
Very useful. Thank You
Thanks a lot!
HELPFUL.
Is there a difference between this and your sql course on AnalystBuilder?
So i wrote one with the sakila schema using address table. Somebody please let me know if this was a correct use of Having:
#shows districts that have more that 5 people(or addresses) saved:
Select district, count(address_id)
From sakila.address
Group by district
Having count(address_id) > 5
#used address_id as it's unique and entries cannot be null for a row
Also aggregate functions include avg, max, min count right? Did i miss anything??
is this series going to replace whats in your bootcamp series?
Yep :)
Hi, I'm trying to transition to data analytics from engineering. Apparent obstacle is that i don't have experience in data. I know that I should learn SQL. Is there any certificate that I can do to proove i'm proficient wioth SQL to future employeers? Thanks
google data analytics certification and azure data fundamentals
@@pushon10 Thanks. Any other certificate that is SQL-specific?
@@macflorek1 idk
✅complete
I am following along but not actually learning, because I'm finding myself just typing what you're typing and I'm not fully thinking through what you're actually doing...
same :/
Same! But what I found helpful is that you can watch the video first and take little notes about what clauses he's using in the vid, etc. then you can open MySQL and try to redo what he did without looking at the video. This worked for me so I hope it helps :D
Alex or anybody here, I need help! Anybody have issues with their sQL management server studio 19 not automatically populating the server name and password in order to connect with the server? Am I missing something here? Can’t get started with Alex’s boot camp until I figure this out. Thank you for any input. It will be greatly appreciated! Maybe it is my computer?
First. 👀
to my heart
@@AlexTheAnalyst Take that, Alex's wife and kids.
done
Interestingly, THIS select gender, avg(age)
from parks_and_recreation.employee_demographics
where age > 40
group by gender
;
gives:
Female 45.0000
Male 52.0000
your Query is saying "give the Average age of those above 40 while grouping by their sex".
-------------------
Female 44
Female 46
Male 61
Male 43
SELECT gender, AVG(age)
FROM parks_and_recreation.employee_demographics
GROUP BY gender
HAVING AVG(age) > 40
;
VS
SELECT gender, AVG(age)
FROM parks_and_recreation.employee_demographics
WHERE age > 40
GROUP BY gender;
Key Differences:
When Filtering Happens:
WHERE clause: Filters individual rows before grouping. Only rows that meet the condition (age > 40) are included in the calculations.
HAVING clause: Filters after grouping. The query groups all the data first, calculates the averages, and then filters the grouped results based on those averages.
Impact on Results:
WHERE: This query only considers employees older than 40 when calculating the average age. Both genders appear because their filtered average age is over 40.
HAVING: This query calculates the average age for all employees first, then filters based on the result. In the example, only the male group’s average age is greater than 40, so only males appear in the result.
Not sure if I am correct but that's because where is using just the age column and not the some aggregate function as the parameter.
From what I understood aggregate functions run only after the Group by statement so just the where age >40 should be fine.