?????????????д?ЩTop??Apply???????÷???????????????壬??????????Щ?????????????????????????????е????????
????Top??Apply?????????????緵??????????3????????????????????????????????????????????????????????????????????????????????id????????????????????????????????????????????????????
????????????????3?????????
SELECT  empid ??
orderid ??
custid ??
orderdate ??
requireddate
FROM    sales.orders AS o1
WHERE   orderid IN ( SELECT TOP 3
orderid
FROM   sales.orders AS o2
WHERE  o2.empid = o1.empid
ORDER BY orderdate DESC ??
orderid DESC )
????????APPLY?????
SELECT  e.empid ??
a.orderid ??
a.custid ??
a.orderdate ??
a.requireddate
FROM    hr.employees AS e
CROSS APPLY ( SELECT TOP 3
orderid ??
custid ??
orderdate ??
requireddate
FROM      sales.orders AS o
WHERE     o.empid = e.empid
ORDER BY  orderdate DESC ??
orderid DESC
) AS a
?????????employees ???empid???????empid???orders???????? ?ù????3??????????????????????????
??????????????????????????????????APPLY??????????????????ROW_NUMBER?????????????????????к????empid???з?????????orderdate desc?? orderid desc ??????????????????У?????к?С??????3???С?
???????£?
????SELECT  orderid ??
????custid ??
????orderdate ??
????requireddate
????FROM    ( SELECT    orderid ??
????custid ??
????orderdate ??
????requireddate ??
????ROW_NUMBER() OVER ( PARTITION BY empid ORDER BY orderdate DESC ?? orderid DESC ) AS rownum
????FROM      sales.orders
????) AS d
????WHERE   rownum  3