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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:05:25+00:00 2026-06-08T15:05:25+00:00

I have a MySQL SELECT query which uses 20 different comparisons within the same

  • 0

I have a MySQL SELECT query which uses 20 different comparisons within the same table. Here’s an example:

SELECT * FROM mytable
WHERE (col1 > (col2 * 0.25))
AND (col5 < col10) .......

I’m trying to calculate percentile ranks based on the order of a column called SCORE within the SELECT results returned. I’ve tried using incremental row numbers and COUNT(*) to get the stock’s rank and total number of results returned but not sure how to assign the same rank where some of the results have the same SCORE.

Here’s the formula that I’m trying to calculate:

((COUNT(lower scores) + (COUNT(same/tied scores) / 2)) * 100) / COUNT(total results)

How do I find the number of lower scores, same/tied scores and total scores within the same result row for calculating percentiles on the fly?

I’m trying to avoid using stored procedures because I want to my application’s admins to tailor the SELECT statement within my applications admin area as needed.

  • 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-06-08T15:05:26+00:00Added an answer on June 8, 2026 at 3:05 pm

    Using Shlomi’s code above, here’s the code that I came up with to calculate percentile ranks (in case anyone wants to calculate these in the future):

    SELECT 
        c.id, c.score, ROUND(((@rank - rank) / @rank) * 100, 2) AS percentile_rank
    FROM
        (SELECT 
        *,
            @prev:=@curr,
            @curr:=a.score,
            @rank:=IF(@prev = @curr, @rank, @rank + 1) AS rank
        FROM
            (SELECT id, score FROM mytable) AS a,
            (SELECT @curr:= null, @prev:= null, @rank:= 0) AS b
    ORDER BY score DESC) AS c;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a MySQL SELECT query which fetches data from 6 tables using Mysql
I have a mysql query Select * from tbl_schoolphotos where Filename like 'glasshouse_1_%' order
I have a MySQL query SELECT * FROM 'redirect' WHERE 'user_id'= \''.$_SESSION['user_id'].' \' ORDER
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
So, I have this mysql query: SELECT member_id, text FROM review WHERE text !=
i have a problem concerning a select query in MYSQL i have two different
I have a query which uses the GROUP_CONCAT of mysql on an integer field.
I have a little script here which uses DOMDocument to get my data from
I have multiple select statements from different tables on the same database. I was
I have the following MySql query: select t1.* from Table1 t1 inner join Table2

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.