Search code examples
mysqlfacebookapprequests

Facebook app count top users


I'm using facebook requests in my app. Lets say for example i have a table like this in my db:

fb_user_id request_id outstanding
id1        rid1       1
id1        rid2       0
id1        rid3       0
id2        rid4       1
id2        rid5       0
id2        rid6       0
id3        rid7       0

outstanding becomes 0 when a user accepts the request. The logic is when the field outstanding is 0 the user that made that request gets 10 points in my app.

Which is the syntax for a mysql query to find out top 100 users with higher points? Ι suppose using order and group by statements..


Solution

  • SELECT TOP 100
       fb_user_id
       SUM(outstanding) As OutstandingTotal
    FROM YourTable
    GROUP BY
       fb_user_id
    ORDER BY DESC
       SUM(outstanding)