whether
ORDER BY CASE
WHEN session_end_time IS NULL THEN session_start_time
ELSE session_end_time
END
work in your DBMS? This does not add a field.
Otherwise, you can calculate it inside a subquery, but not include it in the final sentence SELECT:
SELECT field1, field2 FROM (
SELECT field1, field2, CASE WHEN session_end_time... END AS dummyfield
) Q
ORDER BY Q.dummyfield
source
share