Intermediate SQL Tutorial | Case Statement | Use Cases

Alex The Analyst · Beginner ·📊 Data Analytics & Business Intelligence ·6y ago

Key Takeaways

This video tutorial covers intermediate SQL topics, specifically Case Statements, along with other topics such as Joins, Unions, and Data Types, to help viewers improve their SQL skills for data analysis.

Full Transcript

what is going on everybody my name is Alex Freiburg and today we're gonna be walking through K statements and sequel a case statement allows you to specify condition and then it also allows you to specify what you want returned when that condition is met so we're gonna be using this employee demographics table that we're looking at right here we're gonna walk through the syntax of how to create a cait statement and then we're actually going to some use cases at the end so let's start off by specifying what columns we want let's say we want the first name we want the last name and we want the age now let's just get that information now for our case statement we're gonna be using this age column so we actually want the age to be in there so let's specify where age is not know and run that so now we have a pretty good look at it and let's just order by age just to clean it up a little bit so now I'll start building our case statement so we're gonna say case and then we want to say when now we need to specify what condition we want to look for so let's do when age is greater than 30 then then what do we want to be returned so we want to return that they are old else so that means anything that is not over the age of 30 we want to return young and then you need to specify that you were done with the case statement and so you will write and at the very bottom so this is our first case statement let's run it and see what we get so as you can see a new column was created and if the person is over the age of 30 so 31 and up they're given old and if they're not over the age of 30 they are given young now we can do as many win and then statements as we want so if we want to we can also do when the age is between 27 and 30 then we want to return young and anyone else where they call a so now we have Ryan Howard as the baby anyone between 27 and 30 they're considered a young and anyone over the age of 30 is old now something to note is that the very first condition that is met is going to be returned so if there are multiple conditions that meet the criteria only the very first one is going to be returned and let's demonstrate that real quick so if the age equals 38 then return Stanley because that is Stanley and let's execute this real quick so right here I'm specifying that if it's 38 it should return Stanley but he is right here and it still says old and that's because this condition was already met now if we were to put this right here it should work correctly and let's try it out so now because this condition is met first it is going to return Stanley down here so now let's get into our first use case let's start off by copying this and then commenting it out I only did that because I don't want to rewrite it cuz I'm lazy let's get rid of that and let's look at this real quick we are gonna join on another table that we have really fast and that's gonna be sequel tutorial if you watch my other videos then you know this table and we're gonna do that on employee demographics employee ID is equal to an employee salaried employee ID okay so let's just look at everything in these tables really quick now we are gonna be focusing on the job title in the salary column but we want their first name and last name as well so let's start building that out let's do first name last name job title and salary and let's look at this really quick so now we have our employees and here is the situation we had a fantastic year this year selling paper and corporate has allowed Michael Scott to give out a yearly raise to every sing employee but not every employee is gonna get the same raise because our salesmen are genuinely the people who made us our money and they're gonna get the biggest raises well other people really aren't gonna get into that big of a raise so now let's go through and create a case statement to calculate what their salary will be after they get their raise so let's start off by saying case and when and we want it to say when job titles equal to salesmen so when they are a Salesman what do we want to happen so this is where the calculation occurs so we're gonna take their salary and then we're gonna add their salary times how much their raise is gonna be so the salesman did really really well and we want to give them a 10% raise this year now when their job title is equal to accountant then and we'll take their salary we will give them let's give them a 5% raise it's still very generous there we go and when the job title is equal to H R then it's gonna be the salary plus the salary times and then we're gonna do one all right and else we're just gonna do salary plus salary oops let's do parentheses times and let's just give everyone else a 3% raise and then we'll write end now let's take a look at our results so here's what we have so far we have our first name or last name our job title in our salary that is our current salary and then we're gonna have our salary after we get our raise so I'm going to actually write that up here let's do as salary after raise and let's execute that so let's look at these raises really quick so we have 45,000 and since he is a Salesman he gets a 10% raise which is a raise of $4,500 so 45,000 plus 4,500 is 49 thousand five hundred dollars and as you can see down here we have HR who is making fifty thousand dollars is now he is making fifty thousand dollars and five cents so everybody got a raise so that is our case statement I hope that was helpful I find myself using the case statement a lot when I'm wanting to categorize things or label things and that's kind of what we did in the first example and you can even do calculations like we did in this use case so I hope that was helpful thank you guys so much for watching I really appreciate it if you learned anything from this video be sure to like and 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 Case Statements. 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 · 19 of 60

1 Top 3 Data Analyst Skills in 2020
Top 3 Data Analyst Skills in 2020
Alex The Analyst
2 Truth About Big Companies | Told by a Fortune 500 Data Analyst
Truth About Big Companies | Told by a Fortune 500 Data Analyst
Alex The Analyst
3 Data Analyst Salary | 100k with No Experience
Data Analyst Salary | 100k with No Experience
Alex The Analyst
4 Working at a Big Company Vs Small Company | Told by a Fortune 500 Data Analyst
Working at a Big Company Vs Small Company | Told by a Fortune 500 Data Analyst
Alex The Analyst
5 Data Analyst Resume | Reviewing My Resume! | Fortune 500 Data Analyst
Data Analyst Resume | Reviewing My Resume! | Fortune 500 Data Analyst
Alex The Analyst
6 Data Analyst Resume | Complete Guide To Creating A Data Analyst Resume | Tips + Templates + Examples
Data Analyst Resume | Complete Guide To Creating A Data Analyst Resume | Tips + Templates + Examples
Alex The Analyst
7 Switching Careers to Become a Data Analyst | How I Made the Switch
Switching Careers to Become a Data Analyst | How I Made the Switch
Alex The Analyst
8 Working With a Recruiter to Land Your First Job as a Data Analyst | LinkedIn Recruiters
Working With a Recruiter to Land Your First Job as a Data Analyst | LinkedIn Recruiters
Alex The Analyst
9 Data Analyst Salary in 2020
Data Analyst Salary in 2020
Alex The Analyst
10 Data Analyst Resume | Reviewing YOUR Data Analyst Resumes!
Data Analyst Resume | Reviewing YOUR Data Analyst Resumes!
Alex The Analyst
11 Data Analyst Fact Check |  84k Average Starting Salary?? | The Career Force 2020 Data Analyst Salary
Data Analyst Fact Check | 84k Average Starting Salary?? | The Career Force 2020 Data Analyst Salary
Alex The Analyst
12 SQL Basics Tutorial For Beginners | Installing SQL Server Management Studio and Create Tables | 1/4
SQL Basics Tutorial For Beginners | Installing SQL Server Management Studio and Create Tables | 1/4
Alex The Analyst
13 SQL Basics Tutorial For Beginners | Select + From Statements | 2/4
SQL Basics Tutorial For Beginners | Select + From Statements | 2/4
Alex The Analyst
14 SQL Basics Tutorial For Beginners | Where Statement | 3/4
SQL Basics Tutorial For Beginners | Where Statement | 3/4
Alex The Analyst
15 SQL Basics Tutorial For Beginners | Group By + Order By Statements | 4/4
SQL Basics Tutorial For Beginners | Group By + Order By Statements | 4/4
Alex The Analyst
16 Day in the Life of a Data Analyst | Fortune 500 Edition
Day in the Life of a Data Analyst | Fortune 500 Edition
Alex The Analyst
17 Intermediate SQL Tutorial | Inner/Outer Joins | Use Cases
Intermediate SQL Tutorial | Inner/Outer Joins | Use Cases
Alex The Analyst
18 Intermediate SQL Tutorial | Unions | Union Operator
Intermediate SQL Tutorial | Unions | Union Operator
Alex The Analyst
Intermediate SQL Tutorial | Case Statement | Use Cases
Intermediate SQL Tutorial | Case Statement | Use Cases
Alex The Analyst
20 Intermediate SQL Tutorial | Having Clause
Intermediate SQL Tutorial | Having Clause
Alex The Analyst
21 Intermediate SQL Tutorial | Updating/Deleting Data
Intermediate SQL Tutorial | Updating/Deleting Data
Alex The Analyst
22 Day in the Life of a Data Analyst | Fortune 500 Edition (During Quarantine)
Day in the Life of a Data Analyst | Fortune 500 Edition (During Quarantine)
Alex The Analyst
23 Data Analyst Interview Questions | Phone + In-Person Interview Questions
Data Analyst Interview Questions | Phone + In-Person Interview Questions
Alex The Analyst
24 SQL Interview Questions and Answers for Beginners | Data Analyst Interview Questions
SQL Interview Questions and Answers for Beginners | Data Analyst Interview Questions
Alex The Analyst
25 Data Analyst Interview Questions | What To Say vs What NOT To Say
Data Analyst Interview Questions | What To Say vs What NOT To Say
Alex The Analyst
26 Data Analyst Interviews | Salary Negotiation
Data Analyst Interviews | Salary Negotiation
Alex The Analyst
27 Data Analyst Q&A LIVE
Data Analyst Q&A LIVE
Alex The Analyst
28 Intermediate SQL Tutorial | Aliasing
Intermediate SQL Tutorial | Aliasing
Alex The Analyst
29 Data Scientist vs Data Analyst | Which Is Right For You?
Data Scientist vs Data Analyst | Which Is Right For You?
Alex The Analyst
30 Best Online Courses for Data Analysts
Best Online Courses for Data Analysts
Alex The Analyst
31 Best Free Online Courses for Data Analysts
Best Free Online Courses for Data Analysts
Alex The Analyst
32 Data Analyst vs Business Analyst | Which Is Right For You?
Data Analyst vs Business Analyst | Which Is Right For You?
Alex The Analyst
33 Scraping Data Off Twitter Using Python | Twitterscraper + NLP + Data Visualization
Scraping Data Off Twitter Using Python | Twitterscraper + NLP + Data Visualization
Alex The Analyst
34 Data Analyst Question and Answer | Answering Your YouTube Questions
Data Analyst Question and Answer | Answering Your YouTube Questions
Alex The Analyst
35 What Does a Data Analyst Actually Do?
What Does a Data Analyst Actually Do?
Alex The Analyst
36 Data Analyst Bootcamps | Are They Worth It?
Data Analyst Bootcamps | Are They Worth It?
Alex The Analyst
37 Top 5 Reasons Not to Become a Data Analyst
Top 5 Reasons Not to Become a Data Analyst
Alex The Analyst
38 Data Analyst Career Path | How to Become a Data Analyst + What to Do Next
Data Analyst Career Path | How to Become a Data Analyst + What to Do Next
Alex The Analyst
39 Live Data Analyst Q&A #3
Live Data Analyst Q&A #3
Alex The Analyst
40 Top 5 Reasons Not to Lie on Your Resume
Top 5 Reasons Not to Lie on Your Resume
Alex The Analyst
41 The Hiring Process from an Interviewer's Perspective | Alex The Analyst Show | Episode 1
The Hiring Process from an Interviewer's Perspective | Alex The Analyst Show | Episode 1
Alex The Analyst
42 Top 5 Reasons Data Analytics is a Good Career Choice
Top 5 Reasons Data Analytics is a Good Career Choice
Alex The Analyst
43 How I Changed Careers to Become a Data Analyst | Alex The Analyst Show | Episode 2
How I Changed Careers to Become a Data Analyst | Alex The Analyst Show | Episode 2
Alex The Analyst
44 Top 5 Reasons You'll Be a Good Data Analyst
Top 5 Reasons You'll Be a Good Data Analyst
Alex The Analyst
45 Self Taught vs Boot Camp vs Degree | Alex The Analyst Show | Episode 3
Self Taught vs Boot Camp vs Degree | Alex The Analyst Show | Episode 3
Alex The Analyst
46 Covid and the Data Analyst Job Market | Alex The Analyst Show | Episode 4
Covid and the Data Analyst Job Market | Alex The Analyst Show | Episode 4
Alex The Analyst
47 Data Analyst Expectations vs Reality
Data Analyst Expectations vs Reality
Alex The Analyst
48 Imposter Syndrome in Tech | Alex The Analyst Show | Episode 5
Imposter Syndrome in Tech | Alex The Analyst Show | Episode 5
Alex The Analyst
49 Top 10 Coursera Courses for Data Analysts
Top 10 Coursera Courses for Data Analysts
Alex The Analyst
50 Working at a Startup vs Fortune 500 Company | Alex The Analyst Show | Episode 6
Working at a Startup vs Fortune 500 Company | Alex The Analyst Show | Episode 6
Alex The Analyst
51 Data Analyst Certifications | Are They Worth It? | Alex The Analyst Show | Episode 7
Data Analyst Certifications | Are They Worth It? | Alex The Analyst Show | Episode 7
Alex The Analyst
52 Top 10 Udemy Courses for Data Analysts
Top 10 Udemy Courses for Data Analysts
Alex The Analyst
53 Asking My Wife Your Questions About Me | Alex The Analyst Show | Episode 8
Asking My Wife Your Questions About Me | Alex The Analyst Show | Episode 8
Alex The Analyst
54 Data Analyst Q&A LIVE #4
Data Analyst Q&A LIVE #4
Alex The Analyst
55 Data Analyst Skills Path | What Skills You NEED to Know
Data Analyst Skills Path | What Skills You NEED to Know
Alex The Analyst
56 What is Analytics Consulting? With John Ariansen | Alex The Analyst Show | Episode 9
What is Analytics Consulting? With John Ariansen | Alex The Analyst Show | Episode 9
Alex The Analyst
57 Solving LeetCode SQL Interview Questions | Part 1/3
Solving LeetCode SQL Interview Questions | Part 1/3
Alex The Analyst
58 What is No Code Analytics? | Alex The Analyst Show | Episode 10
What is No Code Analytics? | Alex The Analyst Show | Episode 10
Alex The Analyst
59 Top 3 Tips on Using LinkedIn to Land a Job
Top 3 Tips on Using LinkedIn to Land a Job
Alex The Analyst
60 Completely Unrealistic Jobs on LinkedIn | Alex The Analyst Show | Episode 11
Completely Unrealistic Jobs on LinkedIn | Alex The Analyst Show | Episode 11
Alex The Analyst

This video tutorial teaches intermediate SQL concepts, focusing on Case Statements, to help viewers enhance their data analysis skills. It covers various topics, including Joins, Unions, and Data Types, and provides resources for further learning. By watching this video, viewers can improve their SQL skills and become more proficient in data analysis.

Key Takeaways
  1. Learn the basics of SQL
  2. Understand Case Statements and their use cases
  3. Practice writing SQL queries with Case Statements
  4. Analyze data using SQL
  5. Perform data manipulation using SQL
💡 Mastering Case Statements in SQL can help data analysts make more informed decisions by allowing them to manipulate and analyze data more effectively.

Related AI Lessons

Up next
Spreadsheet Guy Meets the CFO: "Define How Much"
Digital Transformation with Eric Kimberling
Watch →