✅ Solved a SQL problem on LeetCode — Day 44 of my SQL Journey 💪 IP addresses look structured… but validating them isn’t always simple 🌐 Today’s problem was about identifying invalid IP addresses — not just formatting issues, but logical errors inside each segment. I used string functions and conditional checks to: • Split IP into individual octets using string operations • Validate the number of segments (must be 4) • Check if each octet is within the valid range (0–255) • Detect non-numeric values using pattern matching • Count how often each invalid IP appears What I practised: • Working with string parsing in SQL • Using SUBSTRING_INDEX() for segment extraction • Applying REGEXP for pattern validation • Combining multiple validation rules in one query What stood out — Validation isn’t just about format… it’s about the rules behind the format. A value can look correct, but still logically invalid. That’s where careful checking matters. SQL isn’t just for analysis. It can also enforce data quality. Consistent learning, one query at a time 🚀 #SQL #LeetCode #SQLPractice #DataAnalytics #LearningInPublic
Validating IP Addresses with SQL on LeetCode
More Relevant Posts
-
🚀 Day 39/100 – LeetCode SQL Challenge 🔹 Problem: Find Valid Emails Today’s challenge was about filtering valid email addresses using SQL based on specific rules. 📌 Problem Requirements: Exactly one @ symbol Must end with .com Before @ → only letters, numbers, underscore Domain name → only letters 💡 My Approach: Used REGEXP for pattern matching Defined a strict pattern to validate email format Applied filtering conditions directly in SQL query Sorted the result using ORDER BY user_id 🧠 What I Learned: Difference between LIKE and REGEXP How to write regex patterns in SQL Importance of escaping special characters like . Real-world use of SQL in data validation ⚡ Key Insight: Simple-looking problems can test your understanding of string patterns and edge cases deeply. ✅ Step by step improvement in SQL skills! #Day39 #LeetCode #SQL #DSA #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
💡 𝐂𝐓𝐄 𝐦𝐚𝐝𝐞 𝐦𝐲 𝐒𝐐𝐋 𝟏𝟎𝐱 𝐜𝐥𝐞𝐚𝐧𝐞𝐫 Earlier, my SQL queries looked like this: • Nested queries inside nested queries 😵💫 • Hard to read • Even harder to debug Then I discovered CTE (Common Table Expressions)… and everything changed. 👉 Instead of writing one giant messy query, I started breaking it into steps. 𝐋𝐢𝐤𝐞 𝐭𝐡𝐢𝐬: • Step 1: Get base data • Step 2: Apply filters • Step 3: Do aggregations • Step 4: Final output All in a clean, readable flow. 💻 𝐄𝐱𝐚𝐦𝐩𝐥𝐞 𝐦𝐢𝐧𝐝𝐬𝐞𝐭: WITH step1 AS (...), step2 AS (...), step3 AS (...) SELECT * FROM step3; ✨ 𝐖𝐡𝐚𝐭 𝐈 𝐥𝐨𝐯𝐞 𝐚𝐛𝐨𝐮𝐭 𝐂𝐓𝐄: • Makes queries readable • Easy to debug step-by-step • Reusable logic in the same query • Feels like writing code, not chaos 💡 Write SQL in a way that anyone can easily understand. #SQL #DataAnalytics #CTE #DataAnalyst #LearningSQL #TechGrowth 🚀
To view or add a comment, sign in
-
-
✅ Solved a SQL problem on LeetCode — Day 43 of my SQL Journey 💪 Text looks simple… until you try to handle every edge case ✍️ Today’s problem was about transforming text — capitalising the first letter of each word, while handling special cases like hyphens correctly. I used recursive logic and string operations to: • Break text into individual characters using recursive CTE • Track previous characters using window functions • Identify word boundaries and special cases • Apply conditional uppercase/lowercase transformations • Reconstruct the final string using GROUP_CONCAT What I practised: • Recursive CTEs for step-by-step processing • Using LAG() to track character-level context • Writing precise CASE conditions for formatting • Handling edge cases like hyphenated words What stood out — Text transformations aren’t just formatting… they’re about handling context. A single character can change the logic, and missing one condition can break everything. That’s where attention to detail matters most. SQL isn’t just for numbers and aggregations. It can handle complex text logic too. Consistent learning, one query at a time 🚀 #SQL #LeetCode #SQLPractice #DataAnalytics #LearningInPublic
To view or add a comment, sign in
-
-
✅ Solved a SQL problem on LeetCode — Day 49 of my SQL Journey 💪 Consistency isn’t always visible… But patterns reveal it over time 📈 Today’s problem was about identifying users with persistent behaviour — not just active users, but those who show the same action consistently across days. I worked on analysing behaviour patterns to: • Track user actions across consecutive days • Group continuous activity using ROW_NUMBER() logic • Identify streaks by adjusting date gaps • Filter users with meaningful streak length (≥ 5 days) • Select the strongest pattern per user using RANK() What I practised: • Window functions for streak detection • Handling sequential data with date logic • GROUP BY + HAVING for filtering patterns • Translating consistency into measurable conditions What stood out — Activity can be random… Consistency is never random. When actions repeat over time, They stop being noise and become behaviour. That’s where real insights start. SQL doesn’t just analyse data. It uncovers patterns hidden in time. Consistent learning, one query at a time 🚀 #SQL #LeetCode #SQLPractice #DataAnalytics #LearningInPublic
To view or add a comment, sign in
-
-
I’m learning that SQL errors are often not about “complex code” but about small things: query order, punctuation, capitalization, and spelling. What appears to be a logic problem is a missing comma, incorrect keyword placement, or a filter written in the wrong way. The more I practice, the more I see that understanding how SQL thinks makes debugging much easier. Two lessons stood out for me: first, SQL needs structure in the right order, especially knowing where the data is coming from before applying selections and filters. Second, filtering becomes much more powerful when you understand operators like AND, OR, BETWEEN, IN, LIKE, IS NULL, and IS NOT NULL. My biggest takeaway: when debugging SQL, start by checking syntax and query flow first, then review your filtering logic step by step. #SQL #learninginpublic #data
To view or add a comment, sign in
-
I used to nest subqueries for every complex query. Now I use CTEs. The difference is maintainable code. Writing complex SQL gets messy fast. CTEs and subqueries both solve this but in very different ways. • 🧩 CTEs name temporary result sets for reuse in one query. This makes multi-step logic readable and easier to debug later. • 🔍 Subqueries run once per row and nest inside other queries. They often hurt performance and become unreadable in deep nesting. • 🧠 CTEs support recursion for hierarchical data like org charts. Use them when you need to traverse tree structures efficiently. • 🚫 Subqueries cannot reference themselves for recursion. Avoid them for self-referencing data unless you have a simpler case. Before: SELECT e.name, (SELECT name FROM departments WHERE id=e.dept_id) FROM employees e After: WITH dept AS (SELECT id, name FROM departments) SELECT e.name, d.name FROM employees e JOIN dept d ON e.dept_id = d.id Master this by using CTEs for reusable logic blocks and subqueries only for simple scalar values. Which do you use more — CTEs or subqueries?
To view or add a comment, sign in
-
-
call me old fashioned but there’s still something thrilling about writing a sql query solo on a tight deadline. character building.
To view or add a comment, sign in
-
🚀 Day 8 – Data Analysis Journey | Daily SQL Challenge Continuing my daily SQL practice on HackerRank 💻 🧩 Problem Write a query to identify the type of triangle using the given side lengths (A, B, C) in the TRIANGLES table. Output one of the following: • Equilateral → All 3 sides are equal • Isosceles → Any 2 sides are equal • Scalene → All sides are different • Not A Triangle → Values do not satisfy triangle condition 💡 Approach • Used CASE statement to classify triangle types • Applied Triangle Inequality Rule to validate triangle • Checked invalid condition first to avoid wrong classification 🧠 Solution SELECT CASE WHEN A + B <= C OR A + C <= B OR B + C <= A THEN 'Not A Triangle' WHEN A = B AND B = C THEN 'Equilateral' WHEN A = B OR B = C OR A = C THEN 'Isosceles' ELSE 'Scalene' END FROM TRIANGLES; 📚 Key Learning Order of conditions matters in CASE statements. Validating edge cases first ensures accurate results and prevents logical errors. 🔥 Staying consistent and strengthening SQL problem-solving skills step by step! #Day8 #30DaysOfSQL #30DayChallenge #SQL #DataAnalytics #LearningJourney #HackerRank #Beginners #Consistency 🚀
To view or add a comment, sign in
-
-
Stop writing SQL "Inception." Use CTEs instead. 🛑📖 We’ve all been there: opening a query only to find a subquery, inside a subquery, inside another subquery. It’s hard to read, impossible to debug, and a nightmare for your future self. If you want to move from a "Junior" to a "Senior" SQL mindset, you need to master CTEs (Common Table Expressions). Why CTEs are a game-changer: Readability: They allow you to read code from top to bottom, like a story, rather than from the inside out. Reusability: You can reference the same CTE multiple times in one query. No more copy-pasting the same subquery logic! Debugging: You can test each "layer" of your data transformation individually before joining them all together. The Golden Rule: If your logic has more than two levels of nesting, it’s time for a WITH clause. #SQL #DataEngineering #Database #CodingTips #CleanCode #DataAnalytics #CareerGrowth
To view or add a comment, sign in
-
-
I handwrote a complete SQL Roadmap so you don't have to google "where to start with SQL" ever again. 🗺️ Here's everything covered (Beginner → Advanced): 📌 SQL Commands → DDL: CREATE, ALTER, DROP, TRUNCATE → DML: INSERT, UPDATE, DELETE → TCL: COMMIT, ROLLBACK → DCL: GRANT, REVOKE → DQL: SELECT 📌 Clauses → WHERE, HAVING, GROUP BY, ORDER BY, FROM 📌 Joins → INNER, LEFT, RIGHT, FULL OUTER, CROSS, SELF 📌 Subqueries → Scalar, Inline, Correlated, CTE 📌 Indexes → Unique, Bitmap, B-Tree, Composite 📌 Functions → Aggregate, Arithmetic, Date, Char, Analytical, REGEXP 📌 Views, Constraints, Normalization, ACID Properties 📌 Optimization → Explain Plan, Cost, Cardinality, Logical & Relational Sets This is everything you need to go from zero to SQL pro. 💪 💾 Save this post — you'll need it. 🔁 Repost to help someone learning SQL right now. 👉 Follow me for more handcrafted roadmaps like this! Which topic from this roadmap do YOU find hardest? Comment below 👇 #SQL #DataAnalytics #DataEngineering #DataScience #Programming #OracleDatabase #Tech #CareerGrowth #Data #100DaysOfCode
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development