Test Index

Structured Query Language (SQL) Get it on Google PlayDownload on the App Store CBSE Board Videos

© 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 EMPLOYEE
GROUP BY DEPT
HAVING 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
Advertisements
Go to Question: