Back to Browse

day 7 of sql chellagne

11 views
Nov 10, 2025
4:05

Day 7 of hashtag#21DaysSQLChallenge By IDC Sponsored By DPDzero Today I practiced HAVING and GROUP BY clause, with the HospitalBedManagement_Dataset using MySQL Workbench What I Learned Today: -- The SQL HAVING clause is used to filter groups of data after aggregation—especially when using functions like SUM, AVG, or COUNT. Unlike WHERE, which filters rows before grouping, HAVING filters after grouping. 🧠 Key Concepts of the HAVING Clause Purpose: Filters grouped results based on aggregate conditions. Used with: GROUP BY clause and aggregate functions like COUNT(), SUM(), AVG(), MAX(), MIN(). Position in query: Comes after GROUP BY and before ORDER BY. 🔍 Syntax SELECT column1, AGGREGATE_FUNCTION(column2) FROM table_name GROUP BY column1 HAVING AGGREGATE_FUNCTION(column2) condition; 🔄 Difference Between WHERE and HAVING 💡 Tips You can use HAVING without GROUP BY if you're aggregating the entire table. Combine WHERE and HAVING for more control: WHERE filters rows first, HAVING filters grouped results. Daily Challenge: Question: Identify services that refused more than 100 patients in total and had an average patient satisfaction below 80. Show service name, total refused, and average satisfaction. Query: SELECT service,SUM(patients_refused) AS TOTAL_PATIENTS_REFUSED,ROUND(AVG(patient_satisfaction),2) AS AVERAGE_PATIENT_SATISFACTION FROM services_weekly GROUP BY service Execution order: WHERE → GROUP BY → HAVING → ORDER BY Every QUERY tells a story — of patterns, insights, and progress. Day by day, query by query, I'm learning to turn data into decisions. Grateful for this challenge, and excited to keep growing! Grateful to DPDzero and Indian Data Club for giving us this opportunity and making this challenge so interesting💙

Download

1 formats

Video Formats

360pmp45.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

day 7 of sql chellagne | NatokHD