Intermediate SQL Tutorial | Having Clause
Key Takeaways
This video tutorial covers the use of the Having Clause in SQL, specifically in intermediate-level queries, and demonstrates its application in filtering aggregated data.
Full Transcript
what is going on everybody my name is Alex fabric and today we're gonna be looking at the having clause now they haven't class I feel a little bit unappreciated in the sequel community and I feel like it doesn't get a lot of love and so today I wanted to describe how to use it what it's used for so before we use the having clause I want to set up our query here we want to use an aggregate function in the group by statement and then I will show you how to use this having clause so let's look at the job title and let's look at the count of job titles and then down here we need to do group by job title and let's execute this and here is our job titles and here's the count of how many people have those job titles so now let's say we want to look at all the jobs that have more than one person in that specific job so let's do where the count of job title is greater oops is greater than one and let's run that and as you can see we're gonna get this message right here now let's read it an aggregate may not appear in the where clause unless it is in a sub query contained in a having clause or a select list and the column being aggregated is an outer reference what that is basically saying is is we cannot use this aggregate function in the where statement we need to use a having clause so let's get rid of this and let's say having the count of job title greater than one I did the same thing again and let's execute this and we're still gonna get an error now why are we getting that error the reason is is because this having statement is completely dependent on the group by statement because we're performing this after it has been aggregated so this having statement actually needs to go after the group by statement because we can't look at the aggregated information before it's actually aggregated in that group by statement so now let's run this and it worked perfectly so now we only have the jobs that have more than one employee for job title so now let's look at one more example let's do the average let's say salary and let's get rid of this having Clause real quick and just to look at this information let's do order by and we'll do average salary so let's look at this and we have 36,000 265 thousand so in the middle we got forty four thousand five hundred so let's use this having statement and let's stay the average of salary where it is greater than forty five thousand and we actually need to put this right here right after the group by and before the order by so let's run this and see what we get and it works perfectly so now we're looking at the job titles that have an average salary of over forty five thousand dollars so there you go that is the having clause definitely one that is good to know and is very useful in specific situations thank you guys so much for watching I really appreciate it if you liked this video or learned anything today be sure to subscribe below and I'll see you in the next video
Original Description
Take my Full MySQL Course Here: https://bit.ly/3tqOipr
In today's Intermediate SQL lesson we walk through the Having Clause. Very underappreciated in the SQL community if you ask me.
All Topics Covered: Joins, Unions, Case Statements, Updating/Deleting Data, Partition By, Data Types, Aliasing, Views, Having Clause, GetDate(), Primary vs Foreign Key
____________________________________________
SUBSCRIBE!
Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
____________________________________________
RESOURCES:
Coursera Courses:
Google Data Analyst Certification: https://coursera.pxf.io/5bBd62
Data Analysis with Python - https://coursera.pxf.io/BXY3Wy
IBM Data Analysis Specialization - https://coursera.pxf.io/AoYOdR
Tableau Data Visualization - https://coursera.pxf.io/MXYqaN
Udemy Courses:
Python for Data Analysis and Visualization- https://bit.ly/3hhX4LX
Statistics for Data Science - https://bit.ly/37jqDbq
SQL for Data Analysts (SSMS) - https://bit.ly/3fkqEij
Tableau A-Z - http://bit.ly/385lYvN
*Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!*
____________________________________________
Websites:
GitHub: https://github.com/AlexTheAnalyst
____________________________________________
*All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for*
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Alex The Analyst · Alex The Analyst · 20 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
▶
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Top 3 Data Analyst Skills in 2020
Alex The Analyst
Truth About Big Companies | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Salary | 100k with No Experience
Alex The Analyst
Working at a Big Company Vs Small Company | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Reviewing My Resume! | Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Complete Guide To Creating A Data Analyst Resume | Tips + Templates + Examples
Alex The Analyst
Switching Careers to Become a Data Analyst | How I Made the Switch
Alex The Analyst
Working With a Recruiter to Land Your First Job as a Data Analyst | LinkedIn Recruiters
Alex The Analyst
Data Analyst Salary in 2020
Alex The Analyst
Data Analyst Resume | Reviewing YOUR Data Analyst Resumes!
Alex The Analyst
Data Analyst Fact Check | 84k Average Starting Salary?? | The Career Force 2020 Data Analyst Salary
Alex The Analyst
SQL Basics Tutorial For Beginners | Installing SQL Server Management Studio and Create Tables | 1/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Select + From Statements | 2/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Where Statement | 3/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Group By + Order By Statements | 4/4
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition
Alex The Analyst
Intermediate SQL Tutorial | Inner/Outer Joins | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Unions | Union Operator
Alex The Analyst
Intermediate SQL Tutorial | Case Statement | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Having Clause
Alex The Analyst
Intermediate SQL Tutorial | Updating/Deleting Data
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition (During Quarantine)
Alex The Analyst
Data Analyst Interview Questions | Phone + In-Person Interview Questions
Alex The Analyst
SQL Interview Questions and Answers for Beginners | Data Analyst Interview Questions
Alex The Analyst
Data Analyst Interview Questions | What To Say vs What NOT To Say
Alex The Analyst
Data Analyst Interviews | Salary Negotiation
Alex The Analyst
Data Analyst Q&A LIVE
Alex The Analyst
Intermediate SQL Tutorial | Aliasing
Alex The Analyst
Data Scientist vs Data Analyst | Which Is Right For You?
Alex The Analyst
Best Online Courses for Data Analysts
Alex The Analyst
Best Free Online Courses for Data Analysts
Alex The Analyst
Data Analyst vs Business Analyst | Which Is Right For You?
Alex The Analyst
Scraping Data Off Twitter Using Python | Twitterscraper + NLP + Data Visualization
Alex The Analyst
Data Analyst Question and Answer | Answering Your YouTube Questions
Alex The Analyst
What Does a Data Analyst Actually Do?
Alex The Analyst
Data Analyst Bootcamps | Are They Worth It?
Alex The Analyst
Top 5 Reasons Not to Become a Data Analyst
Alex The Analyst
Data Analyst Career Path | How to Become a Data Analyst + What to Do Next
Alex The Analyst
Live Data Analyst Q&A #3
Alex The Analyst
Top 5 Reasons Not to Lie on Your Resume
Alex The Analyst
The Hiring Process from an Interviewer's Perspective | Alex The Analyst Show | Episode 1
Alex The Analyst
Top 5 Reasons Data Analytics is a Good Career Choice
Alex The Analyst
How I Changed Careers to Become a Data Analyst | Alex The Analyst Show | Episode 2
Alex The Analyst
Top 5 Reasons You'll Be a Good Data Analyst
Alex The Analyst
Self Taught vs Boot Camp vs Degree | Alex The Analyst Show | Episode 3
Alex The Analyst
Covid and the Data Analyst Job Market | Alex The Analyst Show | Episode 4
Alex The Analyst
Data Analyst Expectations vs Reality
Alex The Analyst
Imposter Syndrome in Tech | Alex The Analyst Show | Episode 5
Alex The Analyst
Top 10 Coursera Courses for Data Analysts
Alex The Analyst
Working at a Startup vs Fortune 500 Company | Alex The Analyst Show | Episode 6
Alex The Analyst
Data Analyst Certifications | Are They Worth It? | Alex The Analyst Show | Episode 7
Alex The Analyst
Top 10 Udemy Courses for Data Analysts
Alex The Analyst
Asking My Wife Your Questions About Me | Alex The Analyst Show | Episode 8
Alex The Analyst
Data Analyst Q&A LIVE #4
Alex The Analyst
Data Analyst Skills Path | What Skills You NEED to Know
Alex The Analyst
What is Analytics Consulting? With John Ariansen | Alex The Analyst Show | Episode 9
Alex The Analyst
Solving LeetCode SQL Interview Questions | Part 1/3
Alex The Analyst
What is No Code Analytics? | Alex The Analyst Show | Episode 10
Alex The Analyst
Top 3 Tips on Using LinkedIn to Land a Job
Alex The Analyst
Completely Unrealistic Jobs on LinkedIn | Alex The Analyst Show | Episode 11
Alex The Analyst
More on: SQL Analytics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Machine Learning
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Data Science
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Python
Surviving the Data Science Behavioral Interview
Towards Data Science
🎓
Tutor Explanation
DeepCamp AI