What is the GROUP BY clause and why do we use it?
💡 Model Answer
The GROUP BY clause in SQL groups rows that have identical values in specified columns into summary rows. It is typically used with aggregate functions like COUNT, SUM, AVG, MAX, and MIN to perform calculations on each group. For example, SELECT department, AVG(salary) FROM employees GROUP BY department; returns the average salary per department. GROUP BY is essential when you need to analyze data at a higher level of granularity, such as totals per category, averages per region, or counts per status. Without GROUP BY, aggregate functions would return a single value for the entire result set.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500