Question

GROUP BY with HAVING Clause

07 Aug 2026
Answer :
Word Count : 1259
The `GROUP BY` clause with the `HAVING` clause is an important feature of SQL used for organizing, grouping, and filtering data in a relational database. In Database Management Systems, databases usually contain large amounts of information stored in tables. SQL provides various clauses to retrieve meaningful information from these tables. The `GROUP BY` clause is used to arrange rows having the same values into groups, while the `HAVING` clause is used to filter these groups according to a specified condition. Together, they are especially useful when aggregate functions such as `COUNT()`, `SUM()`, `AVG()`, `MAX()`, and `MIN()` are applied to grouped data. The `GROUP BY` clause divides the rows of a table into groups based on one or more columns. Rows having the same value in the specified column or columns are placed in the same group. Aggregate functions can then be applied to each group separately. For example, suppose there is an `Employee` table containing the columns `Employee_ID`, `Employee_Name`, `Department`, and `Salary`. If we want to find the total salary paid to employees in each department, we can use: ```sql SELECT Department, SUM(Salary) FROM Employee GROUP BY Department; ``` In this query, employees are grouped according to their department. The `SUM()` function then calculates the total salary for each department. Thus, instead of displaying individual employee records, the query produces one result for each department. The general syntax of the `GROUP BY` clause is: ```sql SELECT column1, aggregate_function(column2) FROM table_name GROUP BY column1; ``` More than one column can also be specified in the `GROUP BY` clause. For example: ```sql SELECT Department, Job_Title, AVG(Salary) FROM Employee GROUP BY Department, Job_Title; ``` Here, employees are grouped first according to department and then according to job title within each department. The average salary is calculated for every department-job title combination. The `HAVING` clause is used to apply conditions to groups created by the `GROUP BY` clause. It is particularly useful when the condition involves an aggregate function. For example, suppose we want to display only those departments where the total salary is greater than ₹500,000: ```sql SELECT Department, SUM(Salary) AS Total_Salary FROM Employee GROUP BY Department HAVING SUM(Salary) > 500000; ``` The `GROUP BY` clause first creates groups based on departments. The `SUM(Salary)` function calculates the total salary for every department. The `HAVING` clause then retains only those departments whose total salary is greater than ₹500,000. The main difference between `WHERE` and `HAVING` is an important concept in SQL. The `WHERE` clause filters individual rows before grouping takes place, whereas the `HAVING` clause filters groups after grouping and aggregation have taken place. For example: ```sql SELECT Department, AVG(Salary) FROM Employee WHERE Salary > 30000 GROUP BY Department HAVING AVG(Salary) > 50000; ``` In this query, the `WHERE` clause first removes employees whose salary is ₹30,000 or less. The remaining employees are then grouped according to department. The average salary is calculated for each department, and the `HAVING` clause keeps only those departments whose average salary exceeds ₹50,000. The logical processing of such a query can therefore
______ ______ ______ ____ ___.
___ _________ ________ __________ ____ __________ ___ ______ ________ ___ ____ _______.
_________ _____ ____ ______ ____ _______ _________ __________ _________.
___ ____ ___ _______ _____.
________ _________ ______ _____ ___.
_________ ________ _________ _______ ___ __________ ________ ________.
______ ____ ______ ___ __________.
____ ________ _______ ___ __________.
______ _____ __________ ________ ___ __________ ______ __________ ___.
_____ ______ _________ ___ ____.
_________ ____ ___ ______ _______ ___ ______ _____ _______ ______.
____ ____ ________ __________ ________ ______ ______ _____ __________.
______ _____ ___ ___ _______ ___ ___ ___ ______ ________.
_____ ________ ____ _____ ______ ________.
____ _______ ________ ______ ____ ________ __________ ________ ___ ____.
________ ________ ________ ________ _____ ___ _______ ___.
___ _____ _________ ________ ___ ___ _________ ____ __________.
____ ________ ______ _______ ______ ________ _________ ___ ___.
_________ _________ ___ ________ _____ ________ ___.
___ ______ _____ ___ __________ ___ ___ ____ ________ _______.
___ _________ _________ ____ _______ ______ ______ _______ ____ _________.
______ __________ ________ _________ _________ __________ __________ ___ _______ ___ __________.
_____ _________ _______ ____ __________.
___ ____ _____ _________ ______ ______ ________ ______ _____ _____ _________ __________.
______ ____ ___ _________ ______ _________ _____ _____.
________ _______ ___ __________ _________.
______ ________ ___ _________ _________ _______ ______.
________ _________ ______ ______ ______ ____ _________ ________.
_____ ______ _____ _____ _____ ______ _______ _______ _____.
_______ _____ ______ _________ __________ _____ ____ _____ ______ _________.
_______ __________ ________ _____ ____ _______ _________ __________ _______.
___ _______ __________ ______ _____ ____ ________.
______ ____ ______ ______ _____ ___ ________.
__________ _______ __________ _______ _____.
_____ _________ _____ _______ _______ _____ __________ _________ ____ ___ _________ ____.
_____ ___ ____ ________ _________ _____.
_______ ________ ______ _____ ______ ____ ____ ____ ___.
_______ ___ _____ _________ ___ _______ ________ _______.
________ _______ _______ _________ ________ __________ ______ ____ _________ ___.
______ __________ _________ ______ _________ ________ _________ ________ ______.
___ ___ _______ _______ ______ ________ ____.
______ _________ _______ _________ ______ _______ ___ _______.
__________ ___ _________ ______ ________ ___.
______ ____ ______ _____ ___ __________ __________ _____ _____.
____ ____ _____ _______ ______ _________.
________ _______ _____ _______ ______ _________ ________ __________.
_______ ___ __________ __________ _______ __________ ____ _________.
________ _______ __________ ___ __________ _________ ________ ________ ___ __________.
____ _______ _____ ___ ________ ___ _______ __________ _____ __________ _________ _______.
_________ _________ ____ ______ _____ __________ _________ ____.
_____ _____ ___ ______ ___ _____.
___ ___ ____ ____ _______.
___ ____ _________ ___ _____ _____ ______ _______.
_____ ________ ________ ___ ____.
______ ___ ___ _______ _______ ________ _________ _____.
___ _________ __________ ______ __________ ____.
____ ____ __________ ____ ____.
______ _________ ________ ___ __________ ____.
______ ________ _____ ______ _____ ________ ________ _______ ___.
__________ _________ ____ __________ _____ _________.
_________ ___ _______ _______ ___ _____ __________ ______ _________.
________ ___ ___ _______ ____ ____ ________.
_______ __________ _______ ________ _________.
___ _________ ________ ____ __________ _____ ____.
____ ___ ____ _________ _________ _________ ________ _________ __________ ____.
_______ ______ ___ _____ _______ _____ ______ ________ _________ ___ ____ _________.
_______ ____ ______ __________ ____ ___ _______ _________ _______.
________ _______ _____ _______ ______ _______ ___.
______ _________ _____ __________ _____ ______ ________ ______ _________.
_____ ______ ___ ________ ___ _________ ________ _______ ________.
___ _____ ____ __________ ______ ________ _____ _________ __________ ______.
___ ______ ________ ______ _____ _________ _______.
__________ _________ __________ ________ _____.
________ _________ __________ ________ ____ ____.
__________ __________ ________ _________ ________ _______ ________ _______ _______ _______.
_______ ______ _____ _______ ____.
________ _____ __________ _______ __________ ________ _________ _____ ________ ___ _________.
__________ _______ _____ ____ ______ _________ ___ __________ _______ ___ __________ _________.
______ ________ __________ _____ ____ _____ ____ _____ ____.
___ _________ _________ ________ ______ ________ __________ ________.
__________ ___ __________ ________ ________ _________ __________.
_____ ________ ____ ___ _________.
_____ __________ _________ __________ _________ _________ ________ _________ ________ ______ ____.
_________ ____ _______ ________ __________ __________ ____ _____.
_____ ______ _______ ____ _______ _______ ______ ________.
_________ __________ _____ _______ ____ ____ ______ _____.
________ ______ ____ _____ _______.
______ __________ _____ ___ _________ _______ ______ ______ ____.
____ ____ _________ ____ ______ ______ _________.
__________ __________ ______ _____ _____.
________ ___ ___ ___ ______ ___ ___ _____ ________ __________ ______.
_____ __________ _____ _____ _______.
__________ _________ _______ _____ _________.
_____ ______ ________ _________ ______ _____ ________ ______ _______ ____.
______ ______ ________ _________ ________ ___ ______ ___ _______ _______.
________ _______ ______ __________ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 23 2026 2027 - GROUP BY with HAVING Clause | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→