Result of calculation- descending order

hello,
I made calculation from a query .
result of that query need to be presented in desending order based on the calculation result.

how should I do this?
$sql = "select * from lesson where subject = ‘science’ and verified = ‘yes’ ";

from this result, calculation will be made…
it is quite long calculation to show here .

let say the above query returns 5 result, all of these 5 results will be presented with their weight… ‘.$weight.’

now I want the results to be presented according to desendiing weight.
the idea is - order by ‘.$weight.’ desc

thanks for your help

Either:

  1. Perform the calculation in the query, give it an alias, and order by that. This is the best solution performance-wise if you otherwise pull out more rows than you need to figure out which are the top.
SELECT (calculation) AS weight FROM table ORDER BY weight DESC
  1. Calculate the weights, put them into the array, and use usort to define your own sorting function to sort the array by the weights.