赛捷软件论坛's Archiver

vicky.yu 发表于 2024-11-4 17:28

更多HAVING示例

以下SQL语句列出已注册超过10个订单的员工:

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;
 以下SQL语句列出员工“Davolio”或“Fuller”是否已注册超过25个订单:

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;

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.