π§ Key Concepts Explored
π§ͺ Subqueries Simplified
Subqueries are powerful tools in SQL. This week, I learned that:
- Subquery is independent β it returns a value.
- Outer query uses that value, applying it across the main table.
π‘ Golden Rule for Subqueries:
Don't try to understand the whole table first. Instead, zoom in:
- Who should be in the result?
- What is the condition to qualify?
- Whatβs the minimal data I need?
π― 3-Step SQL Problem Solving Template:
| Step | Question | Example Thought |
|---|---|---|
| 1 | Who is the output about? | Authors |
| 2 | What must they have done? | Viewed their own article |
| 3 | Whatβs the SQL logic? |
author_id = viewer_id β SELECT DISTINCT author_id
|
π§° Handy Functions
| Function | Purpose | Syntax Example | Result |
|---|---|---|---|
DATE_ADD() |
Adds interval to date | DATE_ADD('2025-08-06', INTERVAL 1 DAY) |
2025-08-07 |
DATE_SUB() |
Subtracts interval from date | DATE_SUB('2025-08-06', INTERVAL 1 DAY) |
2025-08-05 |
π§Ύ ENUM Usage
ENUM is a data type used to restrict column values to a predefined set.
Example:
status ENUM('Pending', 'Shipped', 'Delivered', 'Cancelled')
- Only those 4 values are allowed.
- You can include numbers, but theyβre stored as strings, not integers.
β LeetCode Practice β 10 Problems Solved π
This week, I tackled and completed 10 beginner-friendly SQL problems:
| Problem No. | Title | Difficulty |
|---|---|---|
| 1757 | Recyclable and Low Fat Products | Easy |
| 584 | Find Customer Referee | Easy |
| 595 | Big Countries | Easy |
| 1148 | Article Views I | Easy |
| 1683 | Invalid Tweets | Easy |
| 1378 | Replace Employee ID With The Unique Identifier | Easy |
| 1068 | Product Sales Analysis I | Easy |
| 1581 | Customer Who Visited but Did Not Make Any Transactions | Easy |
| 197 | Rising Temperature | Easy |
| 1661 | Average Time of Process per Machine | Easy |
| 577 | Employee Bonus | Easy |
π± Whatβs Next?
- Dive deeper into Window Functions
- Explore Advanced Subqueries and Nested Joins
- Build a mini-project using real-world datasets
Thanks for reading! Feel free to connect and share your learning journey too. π¬
#SQL #100DaysOfSQL #LearningJourney #Subqueries #LeetCode
Top comments (0)