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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:41:38+00:00 2026-05-14T08:41:38+00:00

I have a table with these columns: win, los, id … I want to

  • 0

I have a table with these columns: win, los, id …

I want to order the table by this index: win / ( win + los ) * 30 + win / SUM(win) * 70
and then to find the rank for two id’s.
I’m not very good on mysql, so what I wrote is totally wrong. (It uses Perl + DBI + DBD::mysql):

$stmt=$con->prepare("SET @rk := 0");
$stmt=$con->prepare("SELECT rank, id FROM (
                           SELECT @rk := @rk + 1 AS rank,                
                                (win/(win+los)*30+win/SUM(win)*70) AS index,
                                win, los, id 
                          FROM tb_name ORDER BY index DESC) as result 
                   WHERE id=? AND id=?"); 
$stmt -> bind_param ("ii", $id1, $id2);
$stmt -> execute();
$stmt -> bind_result($rk, $idRk); 

And also this query it suppose to run maybe every 5-10 sec for every user, so I’m trying to find something very, very fast.
If it’s necessary I could add, change, delete any column, in order to be as fast as possible.

  • 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-14T08:41:38+00:00Added an answer on May 14, 2026 at 8:41 am

    Try this one:

    SELECT rank, id FROM (
        SELECT @rk := @rk + 1 AS rank,                
        (win/(win+los)*30+win/win_sum*70) AS index, -- SUM(win) -> win_sum
        win, los, id 
        FROM tb_name,
        (SELECT SUM(win) as win_sum FROM tb_name) as ws -- separated SUM(win)
        ORDER BY index DESC) as result
    WHERE id IN (?, ?);    -- id=? AND id=? will never happen, should be OR
    

    A composite index on (‘win’, ‘los’) might be useful.

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

Sidebar

Related Questions

Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY
For examples sake, lets say I have a table containing these columns ID (primary
I have a table with these columns: CombinationID, IndexID, Value There is a sql
In oracle: I have a table rel with these columns (object_id1, object_id2) that relates
Say you have table of some items with these two columns: ItemName Price ....where
I have an exist model (and table) with these columns: id , name ,
I have a table which has columns UserID,DIFFTIME. when I select these columns from
I have a table with these columns create table demo ( ID integer not
Say I have a table Comments with these columns: Id, Comment, Category, CreatedDate, CommenterId
I have a table in my DB called Emplyee and contains these columns :

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.