🗓️ SQL Challenge Day #27: Biggest Single Number 🔹 Find the largest number that appears exactly once! 🔢 🔹 Problem: Return the biggest "single" number (appears only once): ✅ If no such number exists, return NULL 🔹 Solution: SELECT MAX(num) AS num FROM ( SELECT num, COUNT(1) AS cnt FROM MyNumbers GROUP BY num HAVING cnt = 1 ) t; ✅ Result: Accepted 💡 Key Takeaway: **MAX() handles NULL gracefully!** The outer query returns NULL automatically if the inner subquery finds no single numbers – no extra logic needed. This is cleaner than using CASE or IFNULL here. 👇 Your turn: What’s your go-to pattern for handling "return NULL if empty result" scenarios in SQL? #SQL #LeetCode #DataEngineering #ProblemSolving #Coding #LearningInPublic #Database #DataAnalytics
SQL Challenge: Find Biggest Single Number
More Relevant Posts
-
🧼 Wash your hands with good SQL practices before writing queries, or risk infecting your database with bugs! 🤣 #SQL #DataEngineering #SQLTips #CleanCode #DataQuality #DataEngineer #LearnSQL #CodingBestPractices #TechHumor
To view or add a comment, sign in
-
-
🚀 Day 27/100 – LeetCode SQL Challenge 📌 Problem Solved: Biggest Single Number Today’s challenge was about identifying a number that appears only once in a dataset and then finding the largest among them. 🔍 Key Concept: A single number means it appears exactly once. I used: ✔️ GROUP BY to group numbers ✔️ HAVING COUNT(num) = 1 to filter unique values ✔️ MAX() to find the largest among them 💡 What I Learned: Difference between WHERE and HAVING How to filter aggregated data using HAVING Writing optimized queries without unnecessary subqueries Importance of understanding problem keywords like "only once" 🧠 Approach: Count frequency of each number Filter numbers with count = 1 Return the maximum of those numbers 📈 This problem strengthened my understanding of aggregation and filtering in SQL — very useful! 🔥 Consistency is the key — one step closer to mastering SQL! #Day27 #LeetCode #SQL #100DaysOfCode #CodingJourney #PlacementsPreparation #DataAnalytics
To view or add a comment, sign in
-
-
🗓️ SQL Challenge Day #32: Consecutive Numbers 🔹 Find numbers appearing 3+ times in a row! 🔢 🔹 Problem: Identify values with ≥3 consecutive occurrences: ✅ Consecutive = sequential `id` values ✅ Return distinct numbers only 🔹 Solution (Window Function Approach): SELECT distinct num AS ConsecutiveNums FROM ( SELECT num, id, LEAD(id) OVER (PARTITION BY num ORDER BY id) AS l1, LEAD(id, 2) OVER (PARTITION BY num ORDER BY id) AS l2 FROM Logs ) t WHERE l1 - id = 1 AND l2 - l1 = 1; ✅ Result: Accepted 💡 Key Takeaway: **LEAD() checks sequence gaps!** By comparing current `id` with next two `id`s: - `l1 - id = 1` → next record is immediate successor - `l2 - l1 = 1` → third record is also consecutive ⚠️ Why partition by `num`? Ensures we only compare same numbers! 👇 Your turn: Have you used LAG/LEAD for detecting sequences in logs or time-series data? What patterns did you find? #SQL #LeetCode #DataEngineering #ProblemSolving #Coding #LearningInPublic #Database #DataAnalytics
To view or add a comment, sign in
-
-
The Complete SQL Handbook Master these SQL pillars: ✅ Basics: CREATE/INSERT/SELECT/UPDATE/DELETE/ALTER tables ✅ Query power: WHERE/LIKE/IN/BETWEEN/ORDER BY/DISTINCT/LIMIT/OFFSET ✅ Aggregates: COUNT/SUM/MIN/MAX/AVG + GROUP BY/HAVING ✅ Joins mastery: INNER/LEFT/RIGHT/FULL/CROSS/SELF + multi-table ✅ Advanced: Views/Subqueries/Transactions/ACID/Indexes/ER modeling ✅ Functions: String (UPPER/LOWER), Date (strftime), CAST, Math (FLOOR/CEIL/ROUND) ER diagrams → Relational DB + pagination tips included! Data Engineers 💻📊 Level up your SQL game! #SQL #DataEngineering #Joins #GroupBy #Database
To view or add a comment, sign in
-
🗓️ SQL Challenge Day #19: Queries Quality and Percentage 🔹 Measure query performance with quality score and poor query rate! 📊 🔹 Problem: Calculate for each query_name: ✅ Quality = average(rating / position) ✅ Poor query % = percentage with rating < 3 ✅ Round both to 2 decimal places 🔹 Solution: SELECT query_name, ROUND(AVG(rating / position), 2) AS quality, ROUND(AVG(CASE WHEN rating < 3 THEN 1.0 ELSE 0.0 END) * 100, 2) AS poor_query_percentage FROM Queries WHERE query_name IS NOT NULL GROUP BY query_name; ✅ Result: Accepted 💡 Key Takeaway: **AVG(CASE WHEN...)** elegantly calculates percentages in one pass! No need for separate COUNTs – the average of 1s and 0s directly gives the proportion. 👇 Your turn: What's your go-to pattern for calculating percentages in SQL without subqueries? #SQL #LeetCode #DataEngineering #ProblemSolving #Coding #LearningInPublic #Database #DataAnalytics
To view or add a comment, sign in
-
-
A small SQL mistake that can cost you 2 days worth of debugging Let’s say you have a table like this: id | parent_id 1 | NULL (root) 2 | 1 3 | 1 4 | 2 Now you want to find all IDs that are not present in the parent_id column. So you write: SELECT id FROM table_name WHERE id NOT IN ( SELECT parent_id FROM table_name ); This looks perfectly fine right? But the query returns no rows. The reason is the NULL in parent_id. In SQL, NULL represents an unknown value. When NOT IN is used and even one NULL exists in the list, the entire comparison becomes unknown. Since SQL only returns rows where the condition is true, everything gets filtered out. How would you fix this query? #SQL #DATAENGINEER #DATA
To view or add a comment, sign in
-
🚀 Day 42/100 – LeetCode SQL Practice ✅ Problem Solved: Average Time of Process per Machine 💡 My Approach: Each process has a start and end timestamp I joined the table with itself to match: 👉 start row with corresponding end row (same machine_id & process_id) Then calculated: 👉 Time = end - start Finally: 👉 Took average time per machine using AVG() 👉 Used ROUND(..., 3) to format output to 3 decimal places 🧠 What I Learned Today: How to use SELF JOIN in SQL Understanding how to pair related rows (start & end) Using aggregate functions like AVG() Importance of data formatting using ROUND Writing clean queries with GROUP BY 📈 Key Takeaway: “Break the problem → pair related data → compute → aggregate.” #Day42 #100DaysOfCode #LeetCodeSQL #SQL #DataAnalytics #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
My #SQL queries were slow!!! until I understood 𝐉𝐎𝐈𝐍𝐬 properly. I used to think JOINs were just syntax. 𝐈𝐍𝐍𝐄𝐑, 𝐋𝐄𝐅𝐓, 𝐑𝐈𝐆𝐇𝐓, 𝐎𝐔𝐓𝐄𝐑… all looked the same. But in real queries? Choosing the wrong JOIN = wrong data + slow performance. Once I understood this, everything changed. Cleaner queries. Better results. Faster execution. If you’re learning SQL… 𝐌𝐚𝐬𝐭𝐞𝐫 𝐉𝐎𝐈𝐍𝐬 𝐞𝐚𝐫𝐥𝐲, 𝐈𝐭 𝐬𝐚𝐯𝐞𝐬 𝐲𝐨𝐮 𝐡𝐨𝐮𝐫𝐬 𝐥𝐚𝐭𝐞𝐫. #SQL #JOINS #DataAnalytics #Database #LearningInPublic #100DaysOfSQL
To view or add a comment, sign in
-
-
Writing a SQL query is easy. Writing a good SQL query is different. Over time, I realized a few things matter a lot when working with real data: Select only what you need Filter data as early as possible Use indexes wisely Think about execution, not just syntax A query that works is not always a query that scales. This becomes very clear when working with large datasets. Lesson I learned: Always think about performance — not just correctness. What’s one SQL habit that improved your queries? #SQL #SQLServer #DatabaseOptimization #DataEngineering #TechTips
To view or add a comment, sign in
-
-
Stages of running a SQL query: Stage 1: Write the query confidently Stage 2: Hit Run Stage 3: "0 rows returned" Stage 4: Stare at the query for 10 minutes Stage 5: Add a WHERE 1=1 for no reason Stage 6: Realize you spelled the column name wrong Stage 7: It works. Pretend it was always going to work. Tell me your Stage 6 moment in the comments. #SQL #DataAnalyst #DataHumor #CodingMemes #ProgrammerHumor #TechHumor #DataAnalytics #SQLMemes
To view or add a comment, sign in
-
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