Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4553706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:59:05+00:00 2026-05-21T16:59:05+00:00

I have the following table: userid compid round score bonus 2980 3 0 50

  • 0

I have the following table:

  userid  compid round score    bonus
  2980    3     0     50          0
  50        3     0     80          0
  52        3     0     80          0
  55        3     0     20          0
  58        3     0     100         0
  106      3     0     120         0
  555      3     0     50          0
  100     3     0     30          0
  50        3     1     90          0
  52        3     1     50          0
  106      3     1     30          0

I want to be able to not only sum the score and bonus cols per user for all rounds, but rank them accordingly. It should be able to handle ties with the sequence 1,2,2,4,5,5,5,8:

Trick is I don’t want to create a temp table or insert the ranking into the table. Also, i can not limit the return – so it need to rank the entire table regardless of rounds completed.

I have managed to rank the rows but can’t seem to group them with the sum. And of course I have managed the sum separately – I just need to ‘join’ the two steps.

Obtaining sums per user:

SELECT userid,sum(score+bonus) as tscore from entries 
group by userid order by tscore desc

userid  tscore
50      170
106    150
52      130
58      100
2980      50
555    50
100    30
55        20

rank without the score sum : (thanks MySQL Cookbook)

SELECT @rownum := @rownum + 1 AS row,
@rank := IF(@prev_val!=score,@rownum,@rank) AS rank,
userid,
@prev_val := score AS score
FROM exodus_entries ORDER BY score DESC

row   rank  userid      score
1      1    106         120
2      2    58          100
3      3    50          90
4      4    50          80
5      4    52          80
6      6    52          50
7      6    555         50
8      6    2980        50
9      9    100         30
10    9     106         30
11    11    55          20

Thanks for the time and help! All advice welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:59:06+00:00Added an answer on May 21, 2026 at 4:59 pm
    SELECT @rownum := @rownum + 1 AS row,
        @rank := IF(@prev_val!=score,@rownum,@rank) AS rank,
        userid,
        @prev_val := score AS score
    FROM (
        SELECT userid, sum(score+bonus) as score 
        from entries 
        group by userid 
    ) exodus_entries 
    ORDER BY score DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table UserID | User knows -------------------- a | b a
I have following Table with records for ActivityLog: ID, UserId, Category, Created 1 11
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
In SQL Server 2008 I have a user table like the following: Userid Username
I have the following table: Table: UserName Userid User UserUpdate 1 Dan 1/1/2005 1
I have the following table: CREATE TABLE FE_USER ( userid int identity (321,4) CONSTRAINT
I have the following table: Id INT/PK UserId INT/FK CreatedDate DATETIME ActivityMarker INT/FK The
I have something similar to the following table: ================================================ | Id | UserId |
I have the following table: UserID Sub EID 1 TA 1 1 TA 6
I have the following Table named Order Orders Table ___________________________________________________ orderiD | userId |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.