Equations in ORDER BY Operators

Let's say I want to include a sentence wherebased on two columns, X and Z. Then I order (3 * X) + Z DESC. Is it possible? I could not find anything about arithmetic in column order.

Thus, the expression will look like this:

SELECT * FROM mySweetTable 
WHERE U LIKE "as%" or V LIKE "as%" 
ORDER BY (3 * X + Z) DESC
+3
source share
2 answers
SELECT *, (3 * X + Z) as OrderCondition
FROM mySweetTable 
WHERE U LIKE "as%" or V LIKE "as%" 
ORDER BY OrderCondition DESC
+11
source

Assuming X and Z are numeric columns, then there is no problem with that.

+1
source

All Articles