PHP / MYSQL:如果为负,则为ORC ASC;如果为AS子句,则为DESC

So there is a multiplier that is randomly generated. It can be -1 or 1.

$query = "SELECT *, A * $MULTIPLIER1 + B * $MULTIPLIER2 + C * $MULTIPLIER3 AS totalnumber FROM data_table
ORDER BY totalscore DESC
LIMIT 4"

This code itself works. However, if there are TOO many negative multiplier the "totalnumber" becomes a negative number thus ruining the ORDER BY.

I need the "totalnumber" to reverse orders if the number is negative. And descend if the "totalnumber" is positive. Is that possible?

Basically if I have...

  1. 20
  2. 15
  3. -5
  4. -10

Then it becomes (the negative numbers can become abs(values))

  1. 20
  2. 15
  3. 10
  4. 5

or is it possible to ORDER BY totalnumber (100,-100, 99, -99, etc)

You would do this with a two-part order by:

order by (totalnumber > 0) desc,
         abs(totalnumber) desc