Having (SQL)
A Use
To view the present condition formed by the ExamplesTo return a list of department IDs whose total sales exceeded $1000 on the date of January 1, 2000, along with the sum of their sales on that date: SELECT DeptID, SUM(SaleAmount)
FROM Sales
WHERE SaleDate = '2000-01-01'
GROUP BY DeptID
HAVING SUM(SaleAmount) > 1000
Referring to the sample tables in the Join example, the following query will return the list of departments which have more than 1 employee: SELECT DepartmentName, COUNT(*)
FROM Employee
JOIN Department ON Employee.DepartmentID = Department.DepartmentID
GROUP BY DepartmentName
HAVING COUNT(*) > 1;
SELECT * FROM (
SELECT DepartmentName AS deptNam, COUNT(*) AS empCount
FROM Employee AS emp
JOIN Department AS dept ON emp.DepartmentID = dept.DepartmentID
GROUP BY deptNam
) AS grp
WHERE grp.empCount > 1;
References
External links
|
Portal di Ensiklopedia Dunia