Hey Guys,
Hope you’re good. We’re close to ending our 30 days SQL series. Stay tuned. How was Subqueries? Did you understand them? Any confusions let me know in the comments.
Today, we’ll be looking at 2 topics together as Aliases is not too complex and has been covered repeatedly in previous days.
So, let’s get started
Use Of Aliases In SQL
Aliases as used in common English are temporary names that we give to our columns or tables in SQL. They are given by using the ‘AS’ clause in our code. I have repeatedly covered it in our previous days while writing different queries. I’ll combine both the Aliases and Case statements in an example below after I explain case statements.
Use Of CASE Statements In SQL
CASE statements are like if-else statements in SQL. They help us specify a condition for an action to be executed.
To demonstrated CASE statements and Aliases I’ll be using our Video Games dataset. I’ll be using a CASE statement to categorize our games based on critic_score while I give a different name to our title column using an Alias.
So, let’s get started.
I have renamed my title column to game_title using an alias and I have also added another column using a CASE statement that categorizes my games based on critic_score.
These are very easy concepts and should definitely be on your fingertips after you practice it.
Exercise
Here’s what you need to do today:
Load the Hospital Records Dataset
Use Aliases on columns in the Patients table
Use a CASE Statement with any condition you want to specify
Let me know the results in the chat.
I am a BI Engineer working at a Data And AI Firm. I’m trying to help newbies in Data land their first data job and impact as many fellow data professionals as I can. Here’s my contact info:
ajmal7809@gmail.com
bideveloper_ (Discord)