Lesson 28
Employee Salaries | SQL Basic Select | HackerRank Solution
Summary
# Lesson Summary: Employee Salaries Query
In this lesson, we focus on querying employee salaries using SQL from HackerRank. The task involves an employee table with the following columns:
- **employee ID**
- **name**
- **months**
- **salary**
## Objective
Write a SQL query to retrieve a list of employee names with the following conditions:
1. Salary greater than 2000 per month.
2. Employed for less than 10 months.
## Query Explanation
- The query needs to filter results based on the **salary** and **months** conditions.
- We order the results by **employee ID** in ascending order.
### SQL Query Structure
```sql
SELECT name
FROM employee
WHERE salary > 2000
AND months < 10
ORDER BY employee_id;
Conclusion
After executing the query, the output lists employees who meet the criteria of having a salary greater than 2000 and being employed for less than 10 months, sorted by employee ID in ascending order.
Video Transcript
Welcome to another lesson. I will do employee salaries from the basic select subsection
of the SQL section hacker rank. So we're given the stable employee that has the columns
employee ID, name, months, and salary. Write a query that prints the list of employee names,
so we only care about employee names column, and having a salary greater than 2k per month
and been employed for less than 10 months. So we have two conditions here for the where,
right? We have the salary has to be greater than 2000 and the months has to be less than 10.
So the result of ascending is sending employee ID. So we do an order buy for that on the employee
ID column. So let's get to it. We're going to select and we want to care about name column
from what's the table here employee where and we have two conditions, right? So the salary column
that's an integer has to be greater than 2000 and we have another column for months has to be
less than 10 months in the job here. And because we need to order by we do an order buy. And what's
the column we want to sort by is the employee ID. And it's ascending so ASC, but ASC is default.
So you can write it or not. So I can just eliminate it. It's implicitly ASC. Let's click submit code.
And there you go. According to this data, those are the employees that make a salary greater than
2000 per month and been there on the job for less than 10 months. And we ordered by the ascending
employee ID. And that's employee salaries.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: