--Drop Sales.Quotas table if it exists
IF OBJECT_ID (N 'Sales.Quotas' , N 'U' ) IS NOT NULL
DROP TABLE Sales.Quotas
GO
--Create Sales.Quotas table
SELECT e.FirstName, e.LastName, q.SalesQuota AS Quota,
DATENAME(m,q.QuotaDate) AS [ MONTH ], YEAR (q.QuotaDate) AS [ YEAR ]
INTO Sales.Quotas
FROM Sales.SalesPersonQuotaHistory q
INNER JOIN HumanResources.vEmployee e
ON q.SalesPersonID = e.EmployeeID
WHERE SalesQuota BETWEEN 210000 AND 280000
ORDER BY e.LastName, q.QuotaDate
/*
AS you can see, I simply pull DATA FROM a couple other tables IN the DATABASE IN order TO CREATE a SET OF meaningful test DATA.
Here's the SELECT statement I use to query the new table:
*/
SELECT
ROW_NUMBER() OVER(ORDER BY Quota DESC ) AS [RowNumber],
RANK() OVER(ORDER BY Quota DESC ) AS [Rank],
DENSE_RANK() OVER(ORDER BY Quota DESC ) AS [DenseRank],
NTILE(5) OVER(ORDER BY Quota DESC ) AS [NTile],
LastName, Quota, [ MONTH ], [ YEAR ]
FROM Sales.Quotas