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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:49:23+00:00 2026-06-10T08:49:23+00:00

I am looking to do some basic math on my SELECT query and columns..

  • 0

I am looking to do some basic math on my SELECT query and columns..

SELECT Rider, 
COUNT(if(Result = 1, Result, NULL)) AS "Firsts", 
COUNT(if(Result = 2, Result, NULL)) AS "Seconds", 
COUNT(if(Result = 3, Result, NULL)) AS "Thirds", 
COUNT(if(Result = " ", Result, NULL)) AS "NP",
COUNT(*) AS "Total",
"Firsts"/"Total"*100 AS "S/R"
FROM meeting_master
WHERE RaceDayDate>="2012-01-01"
GROUP BY meeting_master.Rider
ORDER BY Firsts DESC
LIMIT 100

My problem (and lack of MySQL knowledge) is to have the S/R column calculate the math in the 7th line…

  • 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-10T08:49:24+00:00Added an answer on June 10, 2026 at 8:49 am

    You should not use alias in SELECT like this:

    "Firsts"/"Total"*100 AS "S/R"
    

    Instead calculate directly like this:

    COUNT(if(Result = 1, Result, NULL))/COUNT(*) * 100 AS "S/R"
    

    So your query should be:

    SELECT Rider, 
    COUNT(if(Result = 1, Result, NULL)) AS "Firsts", 
    COUNT(if(Result = 2, Result, NULL)) AS "Seconds", 
    COUNT(if(Result = 3, Result, NULL)) AS "Thirds", 
    COUNT(if(Result = " ", Result, NULL)) AS "NP",
    COUNT(*) AS "Total",
    COUNT(if(Result = 1, Result, NULL))/COUNT(*) * 100 AS "S/R"
    FROM meeting_master
    WHERE RaceDayDate>="2012-01-01"
    GROUP BY meeting_master.Rider
    ORDER BY Firsts DESC
    LIMIT 100
    

    Just see SQLFiddle example here.

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

Sidebar

Related Questions

Looking for some help with optimising the query below. Seems to be two bottlenecks
I am using SQL Server 2008. I am trying to do some basic math
I'm looking to add some basic theme support to my web application, with users
I have an aplication which performs some basic morphological analysis, and I am looking
I'm looking for some basic SIFT implementation in MATLAB. I need to write it
I'm looking to add some basic security to an Access .MDB. What I'd like
I am looking for a way to implement some basic scene management in OpenGL
I'm looking for some basic examples of the python 2.7 unittest setUpClass() method. I'm
I am writing a basic windows program and I am looking for some basic
I'm looking to learn Ruby, I have some basic programming experience but would still

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.