Skip to content

Isha2605/LeetCode-SQL-50

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode SQL 50 - Solutions & Notes 🗄️

Clean, commented solutions to LeetCode's SQL 50 Study Plan - organized by SQL concept (joins, aggregation, subqueries, window functions) and difficulty. Each solution includes the approach, alternative queries where interesting, and dialect notes for MySQL.

SQL MySQL LeetCode License


📌 About

The LeetCode SQL 50 Study Plan is a curated set of 50 problems that covers the practical SQL patterns used in data-analyst and analytics-engineer interviews - SELECT filters, joins, aggregation, subqueries, string functions, and window functions. Working through all 50 gives you solid coverage of the queries you'll write in a real job.

This repo is my working solution set. I'm writing each solution with readable formatting and a short comment on the approach - so future-me (and anyone else who lands here) can skim a file and understand what it's doing without re-reading the problem.


📊 Progress

Difficulty Completed
🟢 Easy 20
🟡 Medium 20
🔴 Hard 10
Overall 50

🗂️ Index by Topic

Organizing by SQL concept is more useful than by problem number - if you're stuck on a window-function problem, it helps to see every window-function solution together.

Topic Difficulty mix Notes
Select & filter Easy Basic WHERE, DISTINCT, LIMIT, ORDER BY patterns
Basic joins Easy → Medium INNER, LEFT, self-joins, anti-joins
Basic aggregation Easy COUNT, SUM, AVG, GROUP BY fundamentals
Sorting & grouping Easy → Medium HAVING, composite grouping, tie-breaking
Advanced joins Medium Multi-table joins, conditional joins, EXISTS
Subqueries Medium Correlated subqueries, IN/NOT IN patterns
String functions Medium CONCAT, SUBSTRING, LIKE, REGEXP
Window functions Medium → Hard RANK, DENSE_RANK, ROW_NUMBER, LAG/LEAD, running totals
CTEs & recursion Hard WITH clauses, recursive queries

📁 Repository Structure

├── Easy/
│   ├── 1757-recyclable-and-low-fat-products.sql
│   ├── ... (one .sql file per problem)
│   └── README.md              # (optional) index of easy problems
├── Medium/
│   └── ... (in progress)
├── Hard/
│   └── ... (in progress)
└── README.md

Solution file template

Every solution file follows the same structure so it's skimmable:

-- Problem: 1757. Recyclable and Low Fat Products
-- Difficulty: Easy
-- Topic: Select / Filter
-- Link: https://leetcode.com/problems/recyclable-and-low-fat-products/

-- Approach:
-- Filter rows where both low_fats = 'Y' and recyclable = 'Y'.
-- Return only the product_id column.

SELECT product_id
FROM Products
WHERE low_fats   = 'Y'
  AND recyclable = 'Y';

-- Complexity: O(n) single scan; no joins or subqueries required.
-- Alternative: could use IN with a subquery, but direct AND is clearest.

💡 How to Use This Repo

  • Learning from it: open the folder for your difficulty level, read the problem link, try it yourself, then compare. The top comment in each file gives the approach in plain English before the SQL.
  • Searching for a pattern: use GitHub's in-repo search (press t in the file browser). Example: search RANK( to see every window-function problem.
  • Running the queries: the queries are written for MySQL 8+. Most are standard enough to run on PostgreSQL, SQL Server, or SQLite with minor tweaks.

⚙️ Dialect Notes

These solutions target MySQL 8+. A few patterns to know when adapting:

Feature MySQL 8+ Others
Window functions ✅ Supported ✅ PostgreSQL, SQL Server, SQLite ≥ 3.25
CTEs (WITH) ✅ Supported ✅ All major engines
Recursive CTEs ✅ Supported ✅ All major engines
REGEXP ✅ Supported ~ / SIMILAR TO in PostgreSQL
LIMIT n OFFSET m ✅ Supported OFFSET … FETCH in SQL Server
Date arithmetic DATEDIFF(a, b) a - b in PostgreSQL

If you're running these against an older MySQL (≤ 5.7), window-function problems need rewrites using self-joins or correlated subqueries.

📬 Contact

Isha Narkhede · Portfolio · LinkedIn · ishajayant207@gmail.com

📝 License

MIT - see LICENSE.

About

Solutions to LeetCode's SQL 50 Study Plan, organized by SQL concept and difficulty. Each solution includes the approach, alternative queries where interesting, and MySQL dialect notes. Actively in progress.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors