As a beginner in Sql Server 2005, i should get some help in getting top 10 from a table.
The scenario is like, a table Invitecount has multiple records for each userid. i have distinct userid's with the following sql query
Select distinct(userid) from inviteCount
For each userid, i get the number of points using the following query
Select sum(points) from invitecount
where UserID = 126429
And after i get the sum, i should have top 10 users with max points. My problem here is with writing all these statements together using arrays, etc.
IF someone could help me, i really appreciate it. Thanks in advance!
Try this:
SELECT TOP 10 userID, SUM(Points)
FROM inviteCount
GROUP BY UserId
ORDER BY SUM(Points) desc
I'm not sure what you mean by using arrays, but this would get you the top ten userIds ordered by the sum of points.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With