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

  • SEARCH
  • Home
  • 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 638075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:41:35+00:00 2026-05-13T20:41:35+00:00

Is it possible to sort on a calculation of 2 rows in mySQL? For

  • 0

Is it possible to sort on a calculation of 2 rows in mySQL? For example, I have 2 rows, lp and ap I’m trying to do something like this:

SELECT * from myTbl WHERE 1 ORDER BY (lp/ap)

Which isn’t throwing an error, but its also not sorting by the results of that calculation. Is there a way to do this, or do I have to store lp/ap in the database?

  • 1 1 Answer
  • 1 View
  • 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-13T20:41:36+00:00Added an answer on May 13, 2026 at 8:41 pm

    Yes, it is possible, and it does work. Check out the following test:

    CREATE TABLE a(a INT, b INT);
    
    INSERT INTO a VALUES (1, 1);
    INSERT INTO a VALUES (1, 2);
    INSERT INTO a VALUES (1, 3);
    INSERT INTO a VALUES (1, 4);
    INSERT INTO a VALUES (1, 5);
    INSERT INTO a VALUES (1, 6);
    INSERT INTO a VALUES (2, 1);
    INSERT INTO a VALUES (2, 2);
    INSERT INTO a VALUES (2, 3);
    INSERT INTO a VALUES (2, 4);
    INSERT INTO a VALUES (2, 5);
    INSERT INTO a VALUES (2, 6);
    
    SELECT a.a, a.b, (a/b) FROM a ORDER BY (a/b);
    
    +------+------+--------+
    | a    | b    | (a/b)  |
    +------+------+--------+
    |    1 |    6 | 0.1667 | 
    |    1 |    5 | 0.2000 | 
    |    1 |    4 | 0.2500 | 
    |    2 |    6 | 0.3333 | 
    |    1 |    3 | 0.3333 | 
    |    2 |    5 | 0.4000 | 
    |    1 |    2 | 0.5000 | 
    |    2 |    4 | 0.5000 | 
    |    2 |    3 | 0.6667 | 
    |    2 |    2 | 1.0000 | 
    |    1 |    1 | 1.0000 | 
    |    2 |    1 | 2.0000 | 
    +------+------+--------+
    

    SELECT a.a, a.b FROM a ORDER BY (a/b); would return the same results.

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

Sidebar

Related Questions

Possible Duplicate: Natural Sort Order in C# I have a list with a lot
Is it possible to sort users by how much karma they have from getting
I would like to know if it is possible to have sort of compile
Is it possible to sort in MySQL by "order by" using a predefined set
Is it possible to sort the values retrieved from MySQL, in say descending id
Is it possible to sort opendir into althabetical order? $user = $fgmembersite->UserFullName(); $handle =
I have a number of very long arrays. No run-time sort is possible. It
Possible Duplicate: how to sort by length of string followed by alphabetical order? I
Possible Duplicate: Sort multidimensional array by multiple keys I am trying to find some
Possible Duplicate: Sort by key of dictionary inside a dictionary in Python I have

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.