Reputation: 3837
MSSQL 2008R2
Say I have two columns, "Name" and "Total"
Name Total
Team1 2556.54
Team2 2204.77
Team3 2141.64
Team4 1401.37
Team5 1220.77
Team6 1149.92
Team7 1130.62
Team8 1073.69
Team9 1059.66
Team10 1028.52
Team11 970.02
Team12 947.85
Team13 886.93
Team14 788.09
Team15 730.99
Is it possible to calculate and identify the rows belonging to the TOP 10%, BOTTOM 15% from the Total Column?
Where 10% and 15% are variables.
if so how?
Thank you in advance.
Upvotes: 0
Views: 188
Reputation: 6477
--Top 10%
SELECT TOP (@top) PERCENT Name, Total
FROM Teams
ORDER BY Total DESC
--bottom 15%
SELECT TOP (@bottom) PERCENT Name, Total
FROM Teams
ORDER BY Total ASC
Upvotes: 1
Reputation: 3837
I apologise, but I forget to mention in the question that 10% and 15% are variables.
EDIT
It seems it you place the variable in parentheses it works
SELECT top (@top)
Upvotes: 1