Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 49 of 58
Marks:
+1,
-0
Explain the usage of HAVING clause in GROUP BY command in RDBMS with the help of an example.
[CBSE 2023 Compartment]
Solution:
Usage:
GROUP BY forms groups of rows having the same value in a column. The HAVING clause puts a condition on these groups, usually on an aggregate function such as COUNT(), SUM(), AVG(), MAX(), MIN(). (WHERE works on individual rows and cannot use aggregate functions.)Example:SELECT DEPT, COUNT(*)FROM EMPLOYEEGROUP BY DEPTHAVING COUNT(*) > 1;This query groups the employees department-wise and displays the number of employees of only those departments that have more than 1 employee. Departments with a single employee are left out by the HAVING condition.
© examsnet.com
Go to Question: