I have a piece of sql code that selects the top 10% of a table. See below a sample of the database table
And this is my code
SELECT TOP 10 PERCENT *,
CONVERT(VARCHAR, (CONVERT(FLOAT, Points)/CONVERT(FLOAT, totalpoints))*100) + '%' PercentPoints
FROM (SELECT *,
SUM(points) OVER() totalpoints
Order by Points desc
So what this code does is add up all the points in the points table, (also works out what percentage of the points each user has) and then displays the top 10%, which in this case will give me "John" and "Dave"
So what I need the sql to do is check if any other records in that table have the same number of points ast the last selected record, and to select it to.
So in the above table, the code shoud return "John", "Dave" and "Mark" as Dave and Mark are on the same amount of points. Does anyone know how I can do this?
Sorry if this is not clear
View Complete Post