James Isaac’s Post

View profile for James Isaac

Data Analyst || BI || Finance || Excel & Power BI Developer || Tableau || SQL

🎄 SQL Advent Calendar Challenge - Day 10! 🎄 It’s the season of resolutions, and we all know how tricky it can be to stick to them. Day 10 of the SQL Advent Calendar brought an interesting challenge: tracking my friends’ New Year’s resolution progress. 📊 The task? Calculate the number of resolutions made, completed, and determine the success percentage for each friend. Then assign a success category: ✅ Green (75%+ success), 🟡 Yellow (50–75%), or 🔴 Red (below 50%). Here’s the SQL query I used to tackle the problem: SELECT    friend_name,   COUNT(resolution_id) AS resolutions_made,   SUM(CASE WHEN is_completed = 1 THEN 1 ELSE 0 END) AS resolutions_completed,   ROUND(SUM(CASE WHEN is_completed = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(resolution_id), 2) AS success_percentage,   CASE      WHEN SUM(CASE WHEN is_completed = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(resolution_id) > 75 THEN 'Green'     WHEN SUM(CASE WHEN is_completed = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(resolution_id) BETWEEN 50 AND 75 THEN 'Yellow'     ELSE 'Red'   END AS success_category FROM    resolutions GROUP BY    friend_name; Key SQL Features in Action: 1️⃣ Aggregations: Using COUNT() and SUM() to calculate the total resolutions and those completed. 2️⃣ Conditional Logic: Leveraging CASE statements to evaluate the success percentage. 3️⃣ Window Dressing with ROUND(): Making sure percentages look polished and professional. The Results: Here’s how my friends are doing: Alice: 🟡 Yellow, 50% success. Bob: 🟡 Yellow, 50% success. Charlie: ✅ Green, 100% success. Diana: 🟡 Yellow, 66.67% success. Looks like Charlie is absolutely crushing it this year! 🎉 As for the others... maybe next year? 😅 🤩 If you’re thinking about your New Year’s resolutions for 2024, aim for a Green Success Category – let’s keep that success rate above 75%! 💪 Why This Matters: This challenge highlights how SQL can turn raw data into meaningful insights. Whether you're tracking resolutions, analyzing business KPIs, or just having fun with data, SQL is a superpower worth honing! 💪 What do you think of this query? Feel free to share your thoughts or ways to optimize it! 🙌 #SQL #DataAnalytics #SQLChallenge #AdventCalendarChallenge #NewYearsResolutions #DataIsBeautiful

  • No alternative text description for this image

To view or add a comment, sign in

Explore topics