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

  • Home
  • SEARCH
  • 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 554401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:20+00:00 2026-05-13T11:42:20+00:00

Hi there coders around the world, I’m working on a project where users can

  • 0

Hi there coders around the world,

I’m working on a project where users can do certain things and gain points for it. To simplify this question let’s say we got 2 tables user and points.

-- table user       -- table points
+---------------+    +-----------------------------+
|  id  |  name  |    |  id  |  points  |  user_id  |
+---------------+    +-----------------------------+
|  1     Tim    |    |  1      5          1        |
|  2     Tom    |    |  2      10         1        |
|  3     Marc   |    |  3      5          1        |
|  4     Tina   |    |  4      12         2        |
|  5     Lutz   |    |  5      2          2        |
+---------------+    |  6      7          1        |
                     |  7      40         3        |
                     |  8      100        1        |
                     +-----------------------------+

Now to get the complete highscore-list I use the following query

SELECT u.*, SUM( p.points ) AS sum_points
FROM user u
LEFT JOIN points p ON p.user_id = u.id
GROUP BY u.id
ORDER BY sum_points DESC

resulting in a fine highscore-list with all users from first to last

+------------------------------+
|  id  |  name  |  sum_points  |
+------------------------------+
|  1     Tim       127         |
|  3     Marc      40          |
|  2     Tom       14          |
|  4     Tina      0           |
|  5     Lutz      0           |
+------------------------------+

Alright back to the question itself. On the profile of a single user I’d like to show his ranking within the highscore-list.

Can this be done using a single query just showing that for example Tom (id=2) is ranked in place 3?

Thanks alot 🙂

  • 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-13T11:42:21+00:00Added an answer on May 13, 2026 at 11:42 am

    The idea is to ask, “how many players rank above @this_user”:

    select count(*) + 1 from 
    (
        /* list of all users */
        SELECT SUM( p.points ) AS sum_points
        FROM user u
        LEFT JOIN points p ON p.user_id = u.id
        GROUP BY u.id        
    ) x
    /* just count the ones with higher sum_points */
    where sum_points > (select sum(points) from points where user_id = @this_user)
    

    Edited to make result 1-based instead of 0-based

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The project i'm currently working on has seen various coders, from various backgrounds. After
There are quite a few of IRC server codes I am working on a
Hi there dear gurus and expert coders. i am not gonna start with im
I apologize if this has been asked here - I've hunted around here and
I'm working with some UK postcode data around 60,000 entries in a SQL 2008
Why would a coder stuff things into __dict__ that can't be used for attribute
As far as I can tell in c++ there is no common base class
I'm working on an application with a map and there is a div in
There are plenty of examples of similar problems littered around the web but none
So I discovered this weird bug, it's so odd and I can't understand why

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.