use Northwind
Select *
FROM orders A
Where EXISTS
(Select COUNT(1)
FROM orders
Where employeeid = A.employeeid AND orderid > A.orderid
HAVING COUNT(1) < 3)
ORDER BY EmployeeID
语义:在库Northwind中查询表Orders里按EmployeeID分组,每个EmployeeID取前三条OrderID最大的记录