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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:15:36+00:00 2026-05-22T01:15:36+00:00

Next weekend we’re having a competition with 3 qualifications a semifinal and a final.

  • 0

Next weekend we’re having a competition with 3 qualifications a semifinal and a final. Only the best 15 participants could compete in the semifinal. Only the best 6 compete in the Finals.

in the qualifications you get a score from 0 to 100 for each qualification

I’m looking to find a way to select the contesters for the semi-final. This should be based on (rank of qualification1) * (rank of qualification2) * (rank of qualification3)

so i need something like:

select id, name, ((.... as RANK_OF_SCORE_1) * (.. as RANK_OF_SCORE_2) * (... as     RANK_OF_SCORE_3)) as qualification_score from participants order by qualification_score desc limit 15

but of course this is not valid mySQL.

Besides this problem if tho contesters have the same score, they should be both included in the semi-finals even if this exceeds the maximum of 15.

For the finals, we would like to select the best 6 of the semi-final scores. If 2 scores are the same we would like to select on the qualifications..

  • 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-22T01:15:36+00:00Added an answer on May 22, 2026 at 1:15 am

    option 1 : use postgres, which support windowing functions (namely RANK() and DENSE_RANK())

    SELECT user_id, score, rank() over (order by score desc) from scores;
    Time : 0.0014 s
    

    option 2 : use a self- join : the rank of a user with score X is (1 +the count(*) of users with score less than X) ; this is likely to be pretty slow

    CREATE TABLE scores( user_id INT PRIMARY KEY, score INT, KEY(score) );
    INSERT INTO scores SELECT id, rand()*100 FROM serie LIMIT 1000;
    
    SELECT a.user_id, a.score, 1+count(b.user_id) AS rank 
        FROM scores a 
        LEFT JOIN scores b ON (b.score>a.score) 
        GROUP BY user_id ORDER BY rank;
    
    +---------+-------+------+
    | user_id | score | rank |
    +---------+-------+------+
    |     381 |   100 |    1 |
    |     777 |   100 |    1 |
    |     586 |   100 |    1 |
    |     907 |   100 |    1 |
    |     790 |   100 |    1 |
    |     253 |    99 |    6 |
    |     393 |    99 |    6 |
    |     429 |    99 |    6 |
    |     376 |    99 |    6 |
    |     857 |    99 |    6 |
    |     293 |    99 |    6 |
    |     156 |    99 |    6 |
    |     167 |    98 |   13 |
    |     594 |    98 |   13 |
    |     690 |    98 |   13 |
    |     510 |    98 |   13 |
    |     436 |    98 |   13 |
    |     671 |    98 |   13 |
    
    time 0.7s
    

    option 3 :

    SET @rownum = 0;
    SELECT a.user_id, a.score, b.r FROM
    scores a
    JOIN (
        SELECT score, min(r) AS r FROM (
            SELECT user_id, score, @rownum:=@rownum+1 AS r 
            FROM scores ORDER BY score DESC
        ) foo GROUP BY score
    ) b USING (score)
    ORDER BY r;
    
    time : 0.0014 s
    

    EDIT

    SET @rownum1 = 0;
    SET @rownum2 = 0;
    SET @rownum3 = 0;
    
    SELECT s.*, s1.r, s2.r, s3.r FROM
    scores s
    JOIN
    (
        SELECT score_1, min(r) AS r FROM (
            SELECT score_1, @rownum1:=@rownum1+1 AS r 
            FROM scores ORDER BY score_1 DESC
        ) foo GROUP BY score_1
    ) s1 USING (score_1) JOIN (
        SELECT score_2, min(r) AS r FROM (
            SELECT score_2, @rownum2:=@rownum2+1 AS r 
            FROM scores ORDER BY score_2 DESC
        ) foo GROUP BY score_2
    ) s2 USING (score_2) JOIN (
        SELECT score_3, min(r) AS r FROM (
            SELECT score_3, @rownum3:=@rownum3+1 AS r 
            FROM scores ORDER BY score_3 DESC
        ) foo GROUP BY score_3
    ) s3 USING (score_3)
    ORDER BY s1.r * s2.r * s3.r;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way in next piece of code to only get the first record?
The next code works perfectly (it changes the font size for -only- the selected
Next to your normal user table user(user_id/user_email/user_pwd/etc), what is the best way to go
i want to get the list of dates of weekend of current month. is
My next project is going to be using Windows Communication Foundation to host Managed
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I am using the next class (simplified for the sake of understandability) to download
With our next major release we are looking to globalize our ASP.Net application and
Background: Over the next month, I'll be giving three talks about or at least
NOTE : I mention the next couple of paragraphs as background. If you just

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.