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...
Then it becomes (the negative numbers can become abs(values))
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