This repository contains SQL practice problems sourced from LeetCode SQL. Each file corresponds to a specific LeetCode question, and the lessons learned from solving these problems are documented below.
This folder contains SQL practice problems from LeetCode. Each file is named after the corresponding LeetCode question.
Below is a table summarizing the key lessons and concepts learned from each LeetCode question.
| LeetCode Question # | Description |
|---|---|
| 618 | Learn pivot |
| 1083 | Computational time for subquery vs. join. |
| 1107 | Using DATEDIFF(date1, date2) to calculate the difference between two dates. |
| 1112 | Window functions. Watch this YouTube tutorial. |
| 1142 | Using IFNULL(value, replace_value) to handle null values. |
| 1158 | Understanding the effect of placing the WHERE clause. |
| 1164 | Performance optimization using JOIN and IN clauses. |
| 1173 | Learning the AVG function. |
| 1179, 1193 | Practicing aggregate functions during GROUP BY. |
| 1193 | Learning DATE_FORMAT for formatting dates. |
| 1204 | Practicing window functions with ORDER BY and PARTITION BY. |
| 1205 | Must practice FULL JOIN, LEFT JOIN, and RIGHT JOIN. |
| 1212 | Practicing and finding better time complexity. |
| 1264 | Practicing and finding better time complexity. |
| 1270 | Practicing JOIN operations. |
| 1285 | Must practice. |
| 1308 | Practicing the OVER clause. |
| 1321 | Must practice. |
| 1341 | Using UNION ALL and LIMIT. |
| 1393 | Learning the CASE function. |
| 1454 | Using DATE_SUB, RANK, window functions, and INTERVAL. |
| 1484 | Learning GROUP_CONCAT. |
| 1517, 1527 | Practicing regular expressions (REGEXP). See notes here. |
| 1613 | Learning Recursive CTEs. See notes here. |
| 1699 | Learning LEAST, GREATEST. |
| 1783 | Conditional Aggregation |
| 2228 | Lag Function |
| 1336 | Recursive CTE |
-
Joins:
INNER JOIN,LEFT JOIN,RIGHT JOIN,FULL JOIN.- Performance optimization using joins.
-
Window Functions:
ROW_NUMBER(),RANK(),DENSE_RANK().PARTITION BYandORDER BY.
-
Date Functions:
DATEDIFF,DATE_FORMAT,DATE_SUB,INTERVAL.
-
Aggregate Functions:
AVG,GROUP_CONCAT,COUNT,SUM.
-
Conditional Logic:
CASEstatements.IFNULLfor handling null values.
-
Recursive CTEs:
- Generating sequences.
- Traversing hierarchical data.
-
Regular Expressions:
- Using
REGEXPfor pattern matching.
- Using