MSSQL 2008R2
假设我有两列,“名称”和“总计”
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
是否可以从总列中计算和识别属于TOP 10%,BOTTOM 15%的行?
其中10%和15%是变量。
如果是这样的话?
提前谢谢。
答案 0 :(得分:1)
--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
答案 1 :(得分:1)
我道歉,但我忘了在问题中提到10%和15%是变量。
修改
似乎你把变量放在它起作用的括号中
SELECT top (@top)