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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:49:35+00:00 2026-05-26T09:49:35+00:00

Very simply, I need to find student grades using SQL. If, for example, I

  • 0

Very simply, I need to find student grades using SQL.
If, for example, I have following table that define grades

Marks (int)
Grade (Char)

and the data like this:

Marks | Grade

__90 | A+

__80 | A

__70 | A-

__60 | B

__50 | C

__40 | D

Okay, having said that, if I have a student that gained marks 73, how do I calculate her grade using above gradings in SQL.

Thank you so much…

  • 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-26T09:49:36+00:00Added an answer on May 26, 2026 at 9:49 am

    Since I didn’t find any way to do it using MySQL, I had to do some PHP programming to achieve the result. The goal is to get the closest value from gradings.

    Okay suppose, we have the grades as defined in my question.

    $MarksObt = 73 <- Marks obtained by the student:
    

    Step 1: Get grades from mysql ordered by Marks in ASC order (ASC order is important):

    SELECT marks, grade FROM gradings ORDER BY marks
    

    Step 2: Create an array variable “$MinGrades”. Loop through the result of above query. Suppose MySQL results are stored in “$Gradings” array. Now on each iteration, do the following:

    1. Subtract the $Grading[‘marks’] From $MarksObt
    2. If result is greater than or equal to 0, add the result to “$MinGrades” array

    Step 3: When loop ends, the “$MinGrades” array’s first element will be the closest value … DONE

    Below is the PHP code that implements the above:

    $MinGrades = array();
    
    foreach($Gradings as $Key=>$Grading){
        $Subtract = $MarksObt - $Grading['marks'];
        if( $Subtract >= 0 )
            array_push($MinGrades, array($Key=>$Subtract))
    }
    
    $GradeKey = key($MinGrades[0]); // Get key of first element in the array
    print $Gradings[$GradeKey]['grade'];
    

    If you have some better approach, please mention here.
    Thanks for your contribution…

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

Sidebar

Related Questions

i have very simple problem. I need to create model, that represent element of
I need a very simple and clear example of how to create an OCX
I have a very basic understanding of shell scripting, but what I need to
Using the Query object in the Google Visualization API , I need to find
I have a WPF application that I need to have users access directories in.
I've looked at the standard but couldn't find any indication that simply writing to
I find myself in a situation that someone else must have got stuck in
I need a very simple menu which probably contains only one or two items:
Sometimes you need to create a very simple single file application in Qt4. However
I need to do a few very simple URL manipulations in Java. Like get

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.