🚀 Day 33 of My SQL Learning Journey Today I solved a HackerRank problem and learned an important SQL concept along the way 🔥 🔹 Problem: Find the maximum total earnings (salary × months) and count how many employees have that earning 🔹 Solution: SELECT (salary * months) AS earnings, COUNT(*) FROM Employee GROUP BY (salary * months) ORDER BY earnings DESC FETCH FIRST 1 ROW ONLY; 🔹 What I Learned (Important 💡): Initially, I used GROUP BY earnings, but it caused an error ❌ 👉 Reason: GROUP BY is executed before SELECT, so column aliases like earnings are not recognized ✔️ Fix: Use the actual expression instead of alias 🔹 Key Concepts: SQL execution order (FROM → WHERE → GROUP BY → SELECT → ORDER BY) Grouping using computed values Writing DB-compatible queries 💡 Debugging errors taught me more than just solving the problem! Step by step towards becoming better 🚀 #SQL #HackerRank #90DaysOfCode #CodingJourney #ProblemSolving
SQL HackerRank Problem Solution and Learning Experience
More Relevant Posts
-
🚀 Day 16/30 – SQL Challenge 🔹 Problem: Find the first year each product was sold along with its details. 🔹 Approach: Used MIN(year) with a JOIN to get the correct records. Also explored using ROW_NUMBER(). 🔹 Learning: Avoid tuple IN queries and prefer JOINs or window functions for better results. #SQL #LeetCode #Day16 #CodingJourney #ProblemSolving #SDE
To view or add a comment, sign in
-
-
SQL Progress: Logic & CASE Statements! Today I solved another Medium challenge on LeetCode. This problem was a great lesson in how to calculate percentages and rates directly in SQL. What I learned today: 1. AVG with CASE WHEN: I learned that I can use AVG(CASE WHEN condition THEN 1.0 ELSE 0.0 END) to calculate a rate. It’s a very clear way. 2. Handling NULLs in Rates: By using a LEFT JOIN between the Signups and Confirmations tables, I ensured that users with no actions are still included, and the AVG function automatically treats them as 0 if they don't meet the "confirmed" criteria. 3. Precision with ROUND: Used ROUND(..., 2) to make sure the final confirmation rate is clean and meets the required format(0.00). I would love to learn from your experience: is ther another methods cleaner? قليل مستمر خير من كثير منقطع #SQL #DataEngineering #PostgreSQL #LeetCode #100DaysOfCode #DataAnalytics #ProblemSolving
To view or add a comment, sign in
-
-
LEETCODE I’m currently deep in the trenches of the SQL 50 challenge, and let’s just say... it’s a mood. One minute, I’m staring at a "Wrong Answer" screen, questioning if I even know what a JOIN is anymore. The logic seems perfect, the syntax is clean, but the test case just won't budge. It’s frustrating, it’s humbling, and it’s a total brain-burn. But then... it happens. You tweak one subquery, add a HAVING clause, or fix a DISTINCT count, and you hit that Submit button. Seeing that green "Accepted" text pop up is a massive hit of dopamine. There’s no feeling quite like beating 78% of other users with a query you just built from scratch. It makes every "Wrong Answer" worth it. What I’m learning through the grind: Edge Cases are everything: The real world (and LeetCode) is messy. Learning to account for NULLs and duplicates is where the real skill is. Subqueries are powerful: Today’s win involved using a subquery within a HAVING clause to match counts—it’s like a puzzle fitting together. Consistency > Speed: I’m pushing for all 50 questions, but I’m making sure I actually understand the "why" behind every solution. Progress isn't a straight line; it’s a series of red errors until you get that one green win. Getting back to the grind now. Only a few more to go! #LeetCode #SQL #DataAnalysis #100DaysOfCode #CodingLife #DopamineHit #ProblemSolving #TechJourney #MySQL
To view or add a comment, sign in
-
-
Just earned the SQL 50 badge on LeetCode 🎯 Honestly, if you’re starting with SQL - this is all you need. These 50 problems cover almost every important concept, from basics to advanced queries. Big takeaway? 👉 Window Functions are a game changer. Once you get them, a lot of “complex” problems become straightforward. If you’re preparing for interviews or strengthening your backend/data skills, I highly recommend going through this set. 📌 Want MySQL notes covering everything from basic to advanced? Check out my repository: https://lnkd.in/g8CTyMKC Consistency > Everything. #SQL #LeetCode #DataStructures #CodingJourney #BackendDevelopment #Learning #Tech
To view or add a comment, sign in
-
-
🚀 Completed 50 LeetCode SQL Problems! 🧠💻 After learning SQL fundamentals 📚 and practicing on HackerRank, I thought SQL problems would be easy. But solving 50 SQL problems on LeetCode still took a lot of effort and learning. ⚡ The approach that helped me the most: 🔍 Understand the problem and test cases 🧪 Think about edge cases 🧩 Identify the right concept (joins, subqueries, CTEs, window functions) 🪜 Break the problem into small steps and test them ✍️ One simple thing that helped a lot: Notebook & Pen. It might feel boring since many developers jump straight to coding, but writing the logic step-by-step helped me build a clear thought process. Also learned a very important concept: ⚙️ Logical SQL Execution Order FROM → JOIN → ON → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → LIMIT / TOP 💡 In many cases, the logic is correct, but the issue arises in its execution. For me, the objective has never been limited to achieving a green checkmark ✅; rather, it is to understand why the query works and to explore multiple approaches to solving the problem 💡. On to the next challenge! 🚀🔥 #SQL #LeetCode #Learning #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 36 of My SQL Learning Journey Today I worked on a challenging SQL problem involving consecutive records and learned an important lesson along the way 🔥 🔹 Problem: Find records where people count is ≥ 100 for at least 3 consecutive entries 🔗 Problem Link: https://lnkd.in/gNBER5CQ 🔹 Final Solution: WITH temp AS ( SELECT id, visit_date, people, id - ROW_NUMBER() OVER (ORDER BY id) AS grp FROM Stadium WHERE people >= 100 ) SELECT id, visit_date, people FROM temp WHERE grp IN ( SELECT grp FROM temp GROUP BY grp HAVING COUNT(*) >= 3 ); 🔹 Key Learning 💡: The approach was to use ID-based grouping, because the problem depends on consecutive entries (IDs), not consecutive dates. 🔹 Concepts Used: ROW_NUMBER() for sequence handling Grouping consecutive records Window functions + aggregation 💡 Debugging mistakes helped me understand the problem more deeply than just solving it! Consistency continues 🚀 #SQL #LeetCode #WindowFunctions #ProblemSolving #90DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Strengthening My SQL Fundamentals — One Query at a Time! Over the past few days, I’ve been consistently practicing SQL on platforms like LeetCode and HackerRank, focusing on building a strong foundation in data querying and analysis. Here’s what I’ve worked on: 🔹 Basic SELECT queries 🔹 Filtering with WHERE conditions 🔹 Sorting using ORDER BY 🔹 Aggregations (SUM, COUNT, GROUP BY) 🔹 Handling duplicates with DISTINCT 🔹 Pattern matching using LIKE Solved problems like: ✔ Game Play Analysis ✔ Sales Analysis ✔ User Activity (Last 30 Days) ✔ Weather Observation Queries What I’m learning: Consistency > Complexity. Mastering the basics deeply is key to solving advanced problems efficiently. Excited to keep improving and move towards more complex SQL joins, window functions, and real-world datasets 📊 #SQL #DataAnalytics #LearningInPublic #LeetCode #HackerRank #DataScience #TechJourney
To view or add a comment, sign in
-
-
CTEs have quietly become my favorite SQL feature. Not because they're fancy, but because I can come back to a query three months later and actually understand what past-me was doing. 🧐 Instead of one monstrous nested subquery, you get named blocks that read top to bottom. customers_last_year AS (...), their_orders AS (...), final select. That's it. 👇 Recursive CTEs took me longer to warm up to. I avoided them for months because the syntax looked intimidating. Then I had to flatten an employee-manager hierarchy and spent an afternoon fighting it with self-joins before giving up and trying a recursive CTE. Took about 8 lines. Should have learned it sooner. 🔁🤓 Fair warning: they're not always faster. A temp table or indexed subquery sometimes wins on performance. But for making queries you won't hate opening later, CTEs are the move. 💡 #SQL #CTEs #DataAnalytics #Programming
To view or add a comment, sign in
-
🚀 Day 26 – 30 Days SQL LeetCode Challenge Today’s problem was simple but highlights an important real-world scenario 👀 📌 Today's Problem: Article Views I (LeetCode #1148) 🧠 Problem Statement: Find all authors who viewed at least one of their own articles. 💡 Key SQL Concepts Used: • DISTINCT • Filtering with conditions • Comparing columns within the same row 📚 What I Practiced Today: ✔ Comparing values within the same table ✔ Removing duplicates using DISTINCT ✔ Writing clean filtering queries 🔥 This pattern is useful in: • Detecting self-actions (self-purchases, self-views) • Fraud detection • User behavior analysis 🔗 GitHub Repository: https://lnkd.in/e8aV37dA #SQL #LeetCode #DataAnalytics #30DaysOfSQL #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 19/30 of my SQL Problem Solving Challenge 💻 Problem Statement: Find total distance traveled by each user and sort them by highest distance. If distances are equal, sort by name. 🧠 Approach: Used LEFT JOIN to include all users, SUM() with GROUP BY to calculate total distance, and ORDER BY for sorting. Also handled NULL values using COALESCE. ✨ Key Learning: Break the problem into steps, join data, group it, apply aggregation, then sort. Also learned a new function COALESCE, which replaces NULL values by returning the first non-null value (used it here to convert NULL distance into 0). #SQL #30DaysOfSQL #MYSQL #CodingJourney #SDE #ProblemSolving #Streak #DailyLearning
To view or add a comment, sign in
-
Explore related topics
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