A SQL problem-solving repository covering relational database concepts, query optimization techniques, joins, aggregations, subqueries, window functions, and analytical SQL patterns.
This repository contains solutions for the LeetCode Top SQL 50 Study Plan, with all queries tested specifically against the Microsoft SQL Server dialect.
The objective of this repository is to demonstrate practical SQL skills required for backend engineering, data-driven applications, and technical interviews.
- Filtering and sorting
- Joins and relationship handling
- Aggregations and grouping
- Subqueries
- Common Table Expressions (CTEs)
- Window functions
- Ranking and analytical queries
- Date and time manipulation
- String operations
- Data validation techniques
- Self joins and hierarchical relationships
- Writing efficient SQL queries
- Working with relational data models
- Handling business-oriented query scenarios
- Applying SQL Server-specific syntax
- Solving analytical and reporting problems
LeetCode Top SQL 50 Study Plan:
https://leetcode.com/studyplan/top-sql-50/
All solutions below are tested using Microsoft SQL Server.
- Recyclable and Low Fat Products
- Find Customer Referee
- Big Countries
- Article Views I
- Invalid Tweets _6. Replace Employee ID With The Unique Identifier
- Product Sales Analysis I_
- Customer Who Visited but Did Not Make Any Transactions
- Rising Temperature
- Average Time of Process per Machine
- Employee Bonus
- Students and Examinations
- Managers with at Least 5 Direct Reports
- Confirmation Rate
- Not Boring Movies
- Average Selling Price
- Project Employees I
- Percentage of Users Attended a Contest
- Queries Quality and Percentage
- Monthly Transactions I
- Immediate Food Delivery II
- Game Play Analysis IV
- Number of Unique Subjects Taught by Each Teacher
- User Activity for the Past 30 Days I
- Product Sales Analysis III
- Classes More Than 5 Students
- Find Followers Count
- Biggest Single Number
- Customers Who Bought All Products
- The Number of Employees Which Report to Each Employee
- Primary Department for Each Employee
- Triangle Judgement
- Consecutive Numbers
- Product Price at a Given Date
- Last Person to Fit in the Bus
- Count Salary Categories
- Employees Whose Manager Left the Company
- Exchange Seats
- Movie Rating
- Restaurant Growth
- Friend Requests II: Who Has the Most Friends
- Investments in 2016
- Department Top Three Salaries
- Fix Names in a Table
- Patients With a Condition
- Delete Duplicate Emails
- Second Highest Salary
- Group Sold Products By The Date
- List the Products Ordered in a Period
- Find Users With Valid E-Mails
- Recyclable and Low Fat Products
SOLUTION:-
- Find Customer Referee
SOLUTION:-
- Big Countries
SOLUTION:-
- Article Views I
SOLUTION:-
- Invalid Tweets
SOLUTION:-
6. Replace Employee ID With The Unique Identifier
SOLUTION:-
- Product Sales Analysis I
SOLUTION:-
- Customer Who Visited but Did Not Make Any Transactions
SOLUTION:-
- Rising Temperature
SOLUTION:-
- Average Time of Process per Machine
SOLUTION:-
- Employee Bonus
SOLUTION:-
12. Students and Examinations
SOLUTION:-
13. Managers with at Least 5 Direct Reports
SOLUTION:-
- Confirmation Rate
SOLUTION:-
- Not Boring Movies
SOLUTION:-
- Average Selling Price
SOLUTION:-
- Project Employees I
SOLUTION:-
18. Percentage of Users Attended a Contest
SOLUTION:-
19. Queries Quality and Percentage
SOLUTION:-
- Monthly Transactions I
SOLUTION:-
- Immediate Food Delivery II
SOLUTION:-
- Game Play Analysis IV
SOLUTION:-
- Number of Unique Subjects Taught by Each Teacher
SOLUTION:-
24. User Activity for the Past 30 Days I
SOLUTION:-
25. Product Sales Analysis III
SOLUTION:-
- Classes More Than 5 Students
SOLUTION:-
- Find Followers Count
SOLUTION:-
- Biggest Single Number
SOLUTION:-
- Customers Who Bought All Products
SOLUTION:-
30. The Number of Employees Which Report to Each Employee
SOLUTION:-
- Primary Department for Each Employee
SOLUTION:-
- Triangle Judgement
SOLUTION:-
- Consecutive Numbers
SOLUTION:-
34. Product Price at a Given Date
SOLUTION:-
35. Last Person to Fit in the Bus
SOLUTION:-
- Count Salary Categories
SOLUTION:-
- Employees Whose Manager Left the Company
SOLUTION:-
38. Exchange Seats
SOLUTION:-
39. Movie Rating
SOLUTION:-
40. Restaurant Growth
SOLUTION:-
- Friend Requests II: Who Has the Most Friends
SOLUTION:-
42. Investments in 2016
SOLUTION:-
- Department Top Three Salaries
SOLUTION:-
- Fix Names in a Table
SOLUTION:-
- Patients With a Condition
SOLUTION:-
46. Delete Duplicate Emails
SOLUTION:-
SOLUTION:-
- Group Sold Products By The Date
SOLUTION:-
- List the Products Ordered in a Period
SOLUTION:-
50. Find Users With Valid E-Mails
SOLUTION:-
ALTERNATIVE (BETTER) SOLUTION










































































































































































