This repository contains a series of SQL practice problems and solutions designed to help learners strengthen their SQL skills. It covers a wide range of topics from basic queries to advanced SQL concepts.
- Basic SELECT queries
- Filtering using WHERE conditions
- Aggregate functions: COUNT, SUM, AVG, MIN, MAX
- String functions: CONCAT, UPPER, LOWER, SUBSTRING
- Numeric functions: ROUND, CEIL, FLOOR, ABS
- Date and time functions: NOW, CURDATE, DATEDIFF
- Conditional functions: CASE, COALESCE, NULLIF
- Sorting with ORDER BY and limiting rows using LIMIT/OFFSET
- Grouping data using GROUP BY and HAVING
- Joins: INNER JOIN, LEFT JOIN, RIGHT JOIN, SELF JOIN
- Ranking and window functions: ROW_NUMBER(), RANK(), DENSE_RANK()
The goal of this repository is to provide a structured way to practice and master SQL through real-life inspired problems. Each problem includes:
- A description of the problem
- Sample data or tables
- SQL query solution with explanations and comments
This is ideal for students, developers, and anyone preparing for SQL interviews or competitive coding challenges.
- Count total employees (
COUNT(*)
) - Find highest salary (
MAX()
) - Find lowest salary (
MIN()
) - Find average salary (
AVG()
) - List employees hired after a specific date (
WHERE
+>=
) - Display employee names in uppercase (
UPPER()
) - Display employee names in lowercase (
LOWER()
) - List first 5 employees (
LIMIT
) - Find employees in a specific department (
WHERE Department = 'IT'
) - Show distinct departments (
DISTINCT
) - Find employees with NULL manager (
IS NULL
) - Find employees whose salary is above 50,000 (
WHERE Salary > 50000
) - Employees whose name starts with a specific letter (
LIKE 'A%'
) - Employees whose name contains a substring (
LIKE '%an%'
) - Simple join: Show employees with their department names (
INNER JOIN Departments
)
- Count employees per department (
GROUP BY
) - Total salary per department (
SUM(Salary) GROUP BY Department
) - Average salary per department (
AVG(Salary) GROUP BY Department
) - Find 2nd highest salary (
MAX()
+ subquery) - Find 3rd highest salary (
MAX()
+ nested subqueries) - Find employees with salary greater than department average (
JOIN
or subquery) - Top 3 highest salaries (
ORDER BY Salary DESC LIMIT 3
) - Count employees joined after 2020 per department (
GROUP BY + WHERE
) - Employees who belong to multiple departments (
JOIN
orGROUP_CONCAT
equivalent) - Employees not in a specific department (
WHERE NOT IN
orLEFT JOIN IS NULL
) - Show employee with their manager name (
SELF JOIN
) - Show employees and their department along with department head (
JOIN
) - Employees whose salary is above average using a subquery
- Department-wise highest and lowest salary (
GROUP BY + MAX/MIN
) - Rank employees by salary using window function (
ROW_NUMBER()
/RANK()
if supported)
✅ These 30 problems are a good mix of:
- Easy → simple filters, aggregates, string functions, simple joins.
- Medium → grouping, subqueries, multiple joins, ranking, and commonly asked SQL interview questions.