SQL HAVING Clause
The SQL HAVING Clause
WHERE 처럼 condtion을 더하는 구문인데,
WHERE과 달리 COUNT()과 같은 aggregate function과 함께 이용할 수 있다.
HAVING Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SQL HAVING Examples
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;
More HAVING Examples
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID)
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;
'Computer Science > Database' 카테고리의 다른 글
W3Schools SQL | #29 SQL ANY ALL 연산자 (0) | 2022.10.28 |
---|---|
W3Schools SQL | #28 SQL EXISTS 연산자 (0) | 2022.10.28 |
W3Schools SQL | #26 SQL GROUP BY STATEMENT (0) | 2022.10.28 |
W3Schools SQL | #25 SQL UNION 연산자 (0) | 2022.10.28 |
W3Schools SQL | #24 SQL SELF JOIN (0) | 2022.10.28 |