Description
The SQL HAVING clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE.
==========================================================================
filter the results so that only departments with sales greater than $5000 will be returned.
SELECT description, SUM(salary) AS "TOTAL SALARY"
FROM employee1
GROUP BY description
HAVING SUM(salary) > 5000;
==========================================================================
• You could use the SQL COUNT function to return the name of the department and the number of employees (in the associated department) that make over less than 7,000 / year.
• The SQL HAVING clause will filter the results so that only departments with greater than 2 employees will be returned.
SELECT description, COUNT(*) AS "Number of descriptions"
FROM employee1
WHERE salary <7000
GROUP BY description
HAVING COUNT(*) >2;
==========================================================================
will return only those departments where the minimum salary is greater than $5,000.
SELECT first_name, MIN(salary) AS "Lowest salary"
FROM employee1
GROUP BY first_name
HAVING MIN(salary) > 5000;
==========================================================================