Skip to content

Repository files navigation

💻 LeetCode SQL 50 - Study Plan Solutions

My comprehensive solutions to the SQL 50 study plan on LeetCode. This repository features optimized queries written in MySQL, organized by topic according to the LeetCode curriculum.

LeetCode SQL 50 BadgeSQL Skill

📁 Project Structure

The solutions are categorized into folders based on the specific SQL concepts they address:

CategoryFocus Areas
SelectBasic data retrieval and filtering (WHERE).
Basic JoinsRelational mapping using INNER, LEFT, and RIGHT JOIN.
Basic Aggregate FunctionsData summarization (COUNT, SUM, AVG, ROUND).
Sorting and GroupingResult organization (GROUP BY, HAVING) and ordering.
Advanced Select and JoinsComplex joins, self-joins, and conditional logic (CASE WHEN).
SubqueriesNested queries and Common Table Expressions (CTE).
Advanced String Functions / RegexString manipulation and pattern matching.

💡 Key Technical Insights

Throughout this challenge, I have mastered the following advanced SQL techniques:

  • Window Functions: Implementing RANK(), DENSE_RANK(), LEAD(), and LAG() for complex analytical tasks.
  • CTEs (Common Table Expressions): Writing clean, modular, and maintainable code using the WITH clause.
  • Complex Filtering: Identifying duplicates or unique records using window-based counting (e.g., the Insurance problem).
  • Running Totals: Calculating cumulative sums and weights (e.g., the Last Person to Fit in the Bus problem).
  • Performance Optimization: Using set-based logic and efficient aggregation over procedural approaches.

🏆 Featured Solutions

#ProblemKey ConceptLink
550Game Play Analysis IVRetention Logic (RANK & LEAD)View Script
1661Average Time of Process per MachineTime Diff with Lead Window FunctionView Script
1321Restaurant GrowthMoving Averages (ROWS BETWEEN)View Script
1907Count Salary CategoriesCustom Categorization with UNIONView Script
585Investments in 2016Multi-level Filtering (COUNT OVER)View Script
1204Last Person to Fit in the BusRunning Totals (Cumulative Sum)View Script

🛠️ How to Use

All solutions have been verified on LeetCode and pass 100% of the test cases. To run these scripts locally:

  1. Ensure you have a MySQL environment set up (e.g., MySQL Workbench, DBeaver).
  2. Clone the repository:
    git clone [https://github.com/Kuba27x/SQL50-Solutions.git](https://github.com/Kuba27x/SQL50-Solutions.git)

About

Optimized MySQL solutions for the LeetCode SQL 50 study plan, covering window functions, CTEs, and advanced joins.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors