Description:
Download 1M+ code from https://codegive.com/2886375
certainly! in this tutorial, we'll explore some interesting sql problems and practice writing sql queries. we will cover different sql concepts, including joins, aggregations, subqueries, and window functions, through practical examples.
setting up
let’s assume we have two tables: `employees` and `departments`. here are the structures and some sample data for each table.
table: employees
| employee_id | first_name | last_name | department_id | salary |
|-------------|------------|-----------|---------------|---------|
| 1 | john | doe | 1 | 60000 |
| 2 | jane | smith | 2 | 75000 |
| 3 | emily | johnson | 1 | 72000 |
| 4 | mike | brown | 3 | 50000 |
| 5 | chris | davis | 2 | 80000 |
table: departments
| department_id | department_name |
|---------------|------------------|
| 1 | engineering |
| 2 | marketing |
| 3 | hr |
problem 1: retrieve all employees with their department names
**sql query:**
```sql
select e.first_name, e.last_name, d.department_name
from employees e
join departments d on e.department_id = d.department_id;
```
**explanation:** this query joins the `employees` table with the `departments` table to retrieve the first name, last name, and department name of each employee.
problem 2: find employees with salaries above average
**sql query:**
```sql
select first_name, last_name, salary
from employees
where salary (select avg(salary) from employees);
```
**explanation:** this query retrieves employees whose salary is greater than the average salary of all employees. the subquery calculates the average salary.
problem 3: count the number of employees in each department
**sql query:**
```sql
select d.department_name, count(e.employee_id) as employee_count
from departments d
left join employees e on d.dep ...
#SQLPractice #SQLQueries #python
SQL practice
SQL queries
database challenges
SQL problem solving
SQL exercise
advanced SQL
SQL skills
SQL tutorials
SQL optimization
SQL functions
query performance
SQL analytics
data manipulation
SQL techniques
SQL learning
Share this link via
Or copy link























