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 6587601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:56:15+00:00 2026-05-25T16:56:15+00:00

I have a game, where for each round player gets a prize and rating

  • 0

I have a game, where for each round player gets a prize and rating by total prize is calculated.
I use such schema:

1) table game_result (user_id, prize, game_date) is used to store results of the games separately (I need it for my statistics)

2) table rating (user_id, total_prize, total_games) is used to store rating data and total_prize, total_games values are updated at the end of each game

3) I need to find user’s total prize and position in rating fast (to display it during the game). Now I use a kind of this query

SET @rank=0;
SELECT @rank:=@rank+1 AS rank, user_id, total_prize, total_games FROM rating order by total_prize where user_id = ? 

but it resorts rating table for each query and is too slow. The issue is that after each game only one row is changed (with total_prize, total_games) of a single player, but to find his new order place I need to resort the whole table, and performance is not feasible.

Is it possible to reorganize tables to improve performance of this operation?

Thanks!

  • 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-25T16:56:16+00:00Added an answer on May 25, 2026 at 4:56 pm
    SELECT COUNT(*)
    FROM rating
    WHERE total_prize <= (SELECT total_prize FROM rating WHERE user_id = ?)
    

    (Or do a separate query and get the total_prize for the user, plus the other columns you need, then count it.)

    Make sure to have an index on total_prize of course.

    (You may need >= instead, depending on what you mean by rank.)

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

Sidebar

Related Questions

I have a game where each player (A total of 5 players play the
I have to simulate a game where each player has turns and needs to
I have a player, game, shot, round and team model. When creating a shot,
I'm developing a game. I want to have game entities each have their own
I have a game server that spawns a thread for each client with forkIO.
I am trying to code a global lookup table of sorts. I have game
I have this game where balloons are coming from bottom and player has to
I have a Game model which has_many Rounds which has_many Shots. Per game, each
I have a game object that manages several sprite objects. Each of the sprites
I currently have a GAME table with two fields user_id, win win = 1

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.