Skip to content

Latest commit

 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

🗄️ SQL Interview Preparation - Top 50 SQL Problems

A SQL problem-solving repository covering relational database concepts, query optimization techniques, joins, aggregations, subqueries, window functions, and analytical SQL patterns.

SQL Server LeetCode


📖 Overview

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.

🛠 SQL Concepts Covered

  • 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

🗄 Database Skills Demonstrated

  • Writing efficient SQL queries
  • Working with relational data models
  • Handling business-oriented query scenarios
  • Applying SQL Server-specific syntax
  • Solving analytical and reporting problems

📚 Reference

LeetCode Top SQL 50 Study Plan:

https://leetcode.com/studyplan/top-sql-50/


✅ SQL Solutions

All solutions below are tested using Microsoft SQL Server.

  1. Recyclable and Low Fat Products
  2. Find Customer Referee
  3. Big Countries
  4. Article Views I
  5. Invalid Tweets _6. Replace Employee ID With The Unique Identifier
  6. Product Sales Analysis I_
  7. Customer Who Visited but Did Not Make Any Transactions
  8. Rising Temperature
  9. Average Time of Process per Machine
  10. Employee Bonus
  11. Students and Examinations
  12. Managers with at Least 5 Direct Reports
  13. Confirmation Rate
  14. Not Boring Movies
  15. Average Selling Price
  16. Project Employees I
  17. Percentage of Users Attended a Contest
  18. Queries Quality and Percentage
  19. Monthly Transactions I
  20. Immediate Food Delivery II
  21. Game Play Analysis IV
  22. Number of Unique Subjects Taught by Each Teacher
  23. User Activity for the Past 30 Days I
  24. Product Sales Analysis III
  25. Classes More Than 5 Students
  26. Find Followers Count
  27. Biggest Single Number
  28. Customers Who Bought All Products
  29. The Number of Employees Which Report to Each Employee
  30. Primary Department for Each Employee
  31. Triangle Judgement
  32. Consecutive Numbers
  33. Product Price at a Given Date
  34. Last Person to Fit in the Bus
  35. Count Salary Categories
  36. Employees Whose Manager Left the Company
  37. Exchange Seats
  38. Movie Rating
  39. Restaurant Growth
  40. Friend Requests II: Who Has the Most Friends
  41. Investments in 2016
  42. Department Top Three Salaries
  43. Fix Names in a Table
  44. Patients With a Condition
  45. Delete Duplicate Emails
  46. Second Highest Salary
  47. Group Sold Products By The Date
  48. List the Products Ordered in a Period
  49. Find Users With Valid E-Mails

  1. Recyclable and Low Fat Products

image image

SOLUTION:-

image


  1. Find Customer Referee

image image

SOLUTION:-

image


  1. Big Countries

image image

SOLUTION:-

image


  1. Article Views I

image image

SOLUTION:-

image


  1. Invalid Tweets

image image

SOLUTION:-

image


6. Replace Employee ID With The Unique Identifier

image

image image

SOLUTION:-

image


  1. Product Sales Analysis I

image image image image

SOLUTION:-

image


  1. Customer Who Visited but Did Not Make Any Transactions

image image image image

SOLUTION:-

image


  1. Rising Temperature

image image

SOLUTION:-

image


  1. Average Time of Process per Machine

image image

SOLUTION:-

image


  1. Employee Bonus

image image image

SOLUTION:-

image


12. Students and Examinations

image

image image image

image

SOLUTION:-

image


13. Managers with at Least 5 Direct Reports

image

image

SOLUTION:-

image


  1. Confirmation Rate

image image image image

SOLUTION:-

image


  1. Not Boring Movies

image image

SOLUTION:-

image


  1. Average Selling Price

image

image image

image

SOLUTION:-

image


  1. Project Employees I

image

image image

image

SOLUTION:-

image


18. Percentage of Users Attended a Contest

image

image image

image

SOLUTION:-

image


19. Queries Quality and Percentage

image image

SOLUTION:-

image


  1. Monthly Transactions I

image image

SOLUTION:-

image


  1. Immediate Food Delivery II

image image

SOLUTION:-

image


  1. Game Play Analysis IV

image image

SOLUTION:-

image


  1. Number of Unique Subjects Taught by Each Teacher

image

image

SOLUTION:-

image


24. User Activity for the Past 30 Days I

image image

SOLUTION:-

image


25. Product Sales Analysis III

image

****image

SOLUTION:-

image


  1. Classes More Than 5 Students

image image

SOLUTION:-

image


  1. Find Followers Count

image image

SOLUTION:-

image


  1. Biggest Single Number

image image

SOLUTION:-

image


  1. Customers Who Bought All Products

image image

SOLUTION:-

image


30. The Number of Employees Which Report to Each Employee

image image

SOLUTION:-

image


  1. Primary Department for Each Employee

image image

SOLUTION:-

image


  1. Triangle Judgement

image

SOLUTION:-

image


  1. Consecutive Numbers

image

SOLUTION:-

image


34. Product Price at a Given Date

image

image

SOLUTION:-

image


35. Last Person to Fit in the Bus

image image

SOLUTION:-

image


  1. Count Salary Categories

image image

SOLUTION:-

image


  1. Employees Whose Manager Left the Company

image image

SOLUTION:-

image


38. Exchange Seats

image

SOLUTION:-

image


39. Movie Rating

image

image image

image

SOLUTION:-

image


40. Restaurant Growth

image

image image

image

SOLUTION:-

image


  1. Friend Requests II: Who Has the Most Friends

image

SOLUTION:-

image


42. Investments in 2016

image image

SOLUTION:-

image


  1. Department Top Three Salaries

image

image image

image

SOLUTION:-

image


  1. Fix Names in a Table

image

image

SOLUTION:-

image


  1. Patients With a Condition

image

image

SOLUTION:-

image


46. Delete Duplicate Emails

image

image

SOLUTION:-

image


47. Second Highest Salary

image

image

SOLUTION:-

image

image
  1. Group Sold Products By The Date

image

image

SOLUTION:-

image


  1. List the Products Ordered in a Period

image

image image

image

SOLUTION:-

image


50. Find Users With Valid E-Mails

image image

SOLUTION:-

image

ALTERNATIVE (BETTER) SOLUTION

image

About

SQL Server solutions for LeetCode Top SQL 50 demonstrating database fundamentals, analytical SQL, joins, and query optimization techniques.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors