SQL HAVING Example

SQL HAVING Example


|OrderID |EmployeeID|ShipperID  |
+--------+----------+-----------+
|10248	 | 5        |	3       |
+--------+----------+-----------+
|10249	 | 6        |	1       |
+--------+----------+-----------+
|10250	 | 4        |	2       |
And a selection from the "Employees" table:

|EmployeeID |LastName |
+-----------+---------+
|1          |Davolio  |
+-----------+---------+
|2          |Fuller   |
+-----------+---------+
|3          |Leverling|
Now we want to find if the employees "Davolio" or "Fuller" have registered more than 25 orders.
We add an ordinary WHERE clause to the SQL statement:
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID
WHERE LastName='Davolio' OR LastName='Fuller'
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 25;

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
сніпети з SQL
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести