I'm trying to write a query that joins 2 tables and will give me the top 5 names and the amount of items they sold at a location between a certain date range i.e. 01-01-2016 through 12-31-2017.
From what I've been researching, This is what I came up with:
SELECT
EmployeeName,
COUNT(ID) AS 'Number of Deals',
CompanyNumber
FROM
(
SELECT
EmployeeName,
DealID,
CompanyNumber,
ROW_NUMBER() OVER (PARTITION BY CompanyNumber ORDER BY DealID) AS rn
FROM Deal
JOIN DealEmployee
ON Deal.DealID. =DealEmployee.DealID AS T
WHERE
Deal.Status = 2 AND
Date BETWEEN '2016-01-01' AND '2017-12-31' AND
EmployeeName != '' AND T.rn <=5
I am hoping to get the the below result:
I am quite the novice, and I know my syntax is incorrect. Any help given would be greatly appreciated