Using Select Numbers
In place of column names, you can enter in the ORDER BY clause one or more integers that refer to the position of items listed in the select list of the Projection clause. You can also use a select number to sort by an expression.
The following example orders by the expression paid_date - order_date and customer_num,
using select numbers in a nested sort:
SELECT order_num, customer_num, paid_date - order_date
FROM orders
ORDER BY 3, 2;
Select numbers are required in the ORDER BY clause when SELECT statements are joined by the UNION or UNION ALL keywords, or when compatible columns in the same position have different names.