-- Using RANK() : this will get you the first 10 employees with the highest salary rates.-- I rather use dense_rank to top 10 salary rates. Since there can be employees with the same salary rate, you can potentially get more than 10 rows, so I think dense_rank accomplishes this better. select drv.BusinessEntityID, drv.Rate, drv.RankBySalary from (SELECT BusinessEntityID, Rate , RANK() OVER (ORDER BY Rate DESC) AS RankBySalary --dense_RANK() OVER (ORDER BY Rate DESC) AS RankBySa
↧