How can I do arithmetic in the ORDER BY clause with a column aliased in my SELECT clause?
1
vote
2
answers
127
views
The following is illegal.
SELECT
schema_id + 2 AS evil_column
FROM
sys.tables
ORDER BY
evil_column + 3;
If you remove the + 3
, then it is legal.
Assuming that I want to do arithmetic with evil_column
and ORDER BY
the result but do not want to repeat the definition of evil_column
anywhere, what are my options?
Asked by J. Mini
(1237 rep)
Sep 8, 2024, 08:29 PM
Last activity: Sep 11, 2024, 04:10 PM
Last activity: Sep 11, 2024, 04:10 PM