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 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

Ask A Question

Stats

  • Questions 276k
  • Answers 276k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use Django's forms framework. May 13, 2026 at 2:46 pm
  • Editorial Team
    Editorial Team added an answer The unresolved symbols are from the GL and GLU libraries.… May 13, 2026 at 2:46 pm
  • Editorial Team
    Editorial Team added an answer Your problems are probably because you've constructed your html wrongly.… May 13, 2026 at 2:46 pm

Related Questions

This is something I've always wondered, and I can't find any mention of it
Hi I have the following code: - (IBAction)runTask:(id)sender { NSTask *proc; NSPipe *output; NSData
I have a application written in wxPython which I want to make multilingual. Our
Warning: very outdated question with an awful idea. Storing code, whether it be PHP,
I just got a few PHP projects which are using a similar kind of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.