Today’s SQL learning focused on solving problem using GROUP BY, HAVING, and subqueries. Problem Statement: Find all matches where the total number of bowled dismissals was greater than or equal to 2 in an over, and this happened more than once in the same match. SQL Query: select match_id from ( select MatcH_id as match_id, Innings_No, Over_id, sum(bowled) as total_bowled from ball_by_ball group by MatcH_id, Innings_No, Over_id ) t where total_bowled >= 2 group by match_id having count(*) >= 2 order by match_id; Key Learnings: ✅ Used subquery to calculate bowled dismissals per over ✅ Applied WHERE to filter overs with 2+ bowled dismissals ✅ Used HAVING COUNT(*) >= 2 to identify matches where it happened multiple times ✅ Improved understanding of multi-level aggregation in SQL 🔗 Project Notebook: https://lnkd.in/g_wxP6GC 📂 Sample Dataset: https://lnkd.in/gB3jZHht #SQL #DataAnalytics #DataScience #LearningJourney #100DaysOfCode #LinkedInLearning #Analytics #Database
SQL Learning: GROUP BY, HAVING, and Subqueries with Match ID
More Relevant Posts
-
🚀 Day 18/50 – LeetCode SQL Challenge (Percentage of Users Attending a Contest) Today’s problem focused on calculating the percentage of users registered in each contest using SQL. 📊 Key Concepts Used: • GROUP BY • COUNT() • Subquery (total users calculation) • ROUND() function 💡 Approach: Calculated total number of users from Users table Grouped data by contest_id Counted number of users in each contest using COUNT(user_id) Calculated percentage using (count / total_users) * 100 Used ROUND to format output to 2 decimal places 👉 Learned how important it is to use subqueries correctly when calculating overall percentages. 🧠 Key Learning: Understanding total vs grouped data is crucial for percentage problems Using 100.0 ensures correct decimal calculation Aggregation with proper logic gives accurate insights 📈 Consistency is the key to mastering SQL #SQL #DataAnalytics #DataAnalyst #LearningInPublic #30DaysChallenge #SQLPractice #Analytics #CareerGrowth #Consistency #DataScience
To view or add a comment, sign in
-
-
SQL Tip of the Day: CASE WHEN THEN Turn raw data into meaningful insights using conditional logic! 💡 Think of it like IF-ELSE in SQL #SQL #DataAnalytics #Learning #InterviewPrep #DataScience #NewtonSchool
To view or add a comment, sign in
-
-
🧠 SQL Challenge of the Day! Think you’ve got solid SQL skills? Let’s put them to the test 👇 📌 Solve the problem in the image 🚫 Try NOT to peek at the comments before attempting ✅ Once you're done, drop your answer below 🔍 Then check the comments to see if you got it right! 💡 Pro tip: Don’t just aim for the correct answer—try optimizing your query too. Let’s see who gets it right! 💪 #SQL #DataAnalytics #CodingChallenge #LearnSQL #DataScience #TechSkills #PracticeMakesPerfect #LinkedInLearning #ChallengeYourself #Analytics
To view or add a comment, sign in
-
-
🚀 Day 28 of My SQL Learning Journey Today, I explored one of the most powerful concepts in SQL — Correlated Subqueries 🔁 💡 Unlike regular subqueries, a correlated subquery depends on the outer query and executes for each row of the main query. � GeeksforGeeks 🔍 What I Learned ✨ A correlated subquery: ✔ Uses values from the outer query ✔ Runs repeatedly for every row ✔ Helps in solving row-by-row comparisons 📌 Example SQL SELECT name, department, salary FROM employees e WHERE salary > ( SELECT AVG(salary) FROM employees WHERE department = e.department ); 👉 This query finds employees earning more than their department average — a perfect real-world use case! ⚡ Key Takeaways 🔹 Think of it like a loop inside SQL 🔹 Very useful for dynamic filtering & comparisons 🔹 Can be slower on large datasets — so use wisely! 🎯 My Insight Correlated subqueries taught me how SQL can think row-by-row, not just table-wise. It feels like unlocking a deeper level of data analysis 🔓 💬 What’s Next? Exploring more advanced SQL concepts to build strong data skills 🚀 #Day28 #SQLLearning #CorrelatedSubquery #DataAnalytics#SQL #LearningJourney #TechGrowth #FutureDataAnalyst
To view or add a comment, sign in
-
-
📊 SQL Learning Journey Today, I learned a new concept in SQL: HAVING clause So far, I’ve covered: ✔️ SELECT & filtering using WHERE (AND / OR, LIKE) ✔️ ORDER BY for sorting ✔️ GROUP BY for grouping data ✔️ INNER JOIN for combining tables 🔍 Today’s focus: HAVING At first, it felt a bit confusing, but here’s the simple way I understood it: 👉 WHERE filters rows 👉 HAVING filters grouped data 💡 Example: If I group users by plan, HAVING helps me filter only those plans where users are more than a certain number. This small concept made a big difference in understanding how to analyze grouped data more effectively. Step by step, getting more comfortable with SQL. 📈 #SQL #DataAnalytics #LearningJourney #SQLPractice
To view or add a comment, sign in
-
-
Your SQL query can be 100% correct… and still give the wrong answer. Here are 5 common SQL pitfalls I’ve seen (and fixed) in real projects 👇 🚀 What’s a SQL mistake that taught you a big lesson? #SQL #DataEngineering #Analytics #Learning #TechCareers
To view or add a comment, sign in
-
-
If you're still relying heavily on subqueries and GROUP BY for everything in SQL, it might be time to level up. Window functions in SQL Server allow you to perform powerful calculations like rankings, running totals, and trend analysis-while still retaining row-level data. This article walks through practical examples using functions like ROW_NUMBER(), RANK(), and more, making it easier to understand and apply in real-world scenarios. 📖 A must-read for anyone working with data. 👉 https://lnkd.in/gQmFTK5t #SQLServer #DataAnalytics #DataEngineering #Developers #LearnSQL #SQL #DataScience #TechSkills #Analytics #Database
To view or add a comment, sign in
-
-
SQL Challenge 9/100 : Best Time to Trade Stock 📈 (Part-4) 💪 Difficulty - Hard 🔗 Part 3: Refer old post You are given a table with stock prices 📊 🎯 Problem Let’s make it tougher 👇 👉 You can make at most 2 transactions 🔁 👉 You cannot hold multiple stocks at the same time 🚫📦 👉 Must sell before buying again 🔄 ❓ Your Task Write a SQL query to: ✅ Return maximum profit 💰 ✅ Also return the buy & sell days for both transactions\ ⚠️ Rules: Max 2 transactions only 🔢 No overlapping 🚫 Buy < Sell always ⏳ No hardcoding ❌ -- Create table CREATE TABLE stock_prices ( day INT, price INT ); -- Insert data INSERT INTO stock_prices (day, price) VALUES (1, 100), (2, 180), (3, 260), (4, 310), (5, 40), (6, 535), (7, 695); Tagging Ankit Bansal Sumit Mittal for better reach Sanjay Gatti #SQL #DataEngineering #SQLChallenge #Analytics #LearnSQL 🚀
To view or add a comment, sign in
-
-
🚀 Day 19/50 – LeetCode SQL Challenge (Queries Quality & Percentage) Today’s problem focused on analyzing query performance by calculating quality and identifying poor queries using SQL. 📊 Key Concepts Used: • Aggregation (AVG, COUNT) • CASE WHEN (conditional logic) • Ratio calculation (rating / position) • ROUND() function 💡 Approach: Calculated query quality using AVG(rating / position) Used CASE WHEN to identify poor queries (rating < 3) Computed poor query percentage using average of conditional values Rounded both metrics to 2 decimal places for better readability 👉 Learned how to convert conditions into numerical values (0/1) and use AVG to directly calculate percentages. 🧠 Key Learning: AVG of 0/1 can be used to calculate percentage efficiently Combining aggregation with conditional logic simplifies complex problems Clean formatting (ROUND) makes results more professional 📈 Consistency in practice is building stronger SQL fundamentals every day #SQL #DataAnalytics #DataAnalyst #LearningInPublic #30DaysChallenge #SQLPractice #Analytics #CareerGrowth #Consistency #DataScience
To view or add a comment, sign in
-
-
🚀 Day 13 – Data Analysis Journey | Daily SQL Challenge Continuing my daily SQL practice on HackerRank 💻 🧩 Problem Query the following two values from the STATION table: • The sum of all values in LAT_N rounded to 2 decimal places • The sum of all values in LONG_W rounded to 2 decimal places 💡 Approach • Used SUM() to calculate total values for both columns • Applied ROUND() function to limit the result to 2 decimal places • Combined both calculations into a single SELECT statement 🧠 Solution SELECT ROUND(SUM(LAT_N), 2), ROUND(SUM(LONG_W), 2) FROM STATION; ⚠️ Challenge Faced Initially, I wrote two separate queries for LAT_N and LONG_W But realized that HackerRank expects the output in a single row with two columns. This helped me understand: 👉 Multiple aggregations can be done in one query 👉 Output format matters as much as logic 📚 Key Learning Efficient SQL queries combine multiple calculations in a single statement, improving performance and readability. 🔥 Staying consistent and improving SQL skills step by step! #Day13 #30DaysOfSQL #SQL #DataAnalytics #LearningJourney #HackerRank #Consistency #Aggregation 🚀
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