Skip to content

Kuba27x/SQL50-Solutions

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 Badge SQL Skill

📁 Project Structure

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

Category Focus Areas
Select Basic data retrieval and filtering (WHERE).
Basic Joins Relational mapping using INNER, LEFT, and RIGHT JOIN.
Basic Aggregate Functions Data summarization (COUNT, SUM, AVG, ROUND).
Sorting and Grouping Result organization (GROUP BY, HAVING) and ordering.
Advanced Select and Joins Complex joins, self-joins, and conditional logic (CASE WHEN).
Subqueries Nested queries and Common Table Expressions (CTE).
Advanced String Functions / Regex String 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

# Problem Key Concept Link
550 Game Play Analysis IV Retention Logic (RANK & LEAD) View Script
1661 Average Time of Process per Machine Time Diff with Lead Window Function View Script
1321 Restaurant Growth Moving Averages (ROWS BETWEEN) View Script
1907 Count Salary Categories Custom Categorization with UNION View Script
585 Investments in 2016 Multi-level Filtering (COUNT OVER) View Script
1204 Last Person to Fit in the Bus Running 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

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors