Sort keys with expressions

You can specify an expression with operators as the sort key for the result table of a SELECT statement.

When you specify an expression with operators as the sort key, the query to which ordering is applied must be a subselect.

Example

Begin general-use programming interface information. The following query is a part of a subselect. The query retrieves the employee numbers, salaries, commissions, and total compensation (salary plus commission) for employees with a total compensation greater than 40000. Order the results by total compensation:
SELECT EMPNO, SALARY, COMM, SALARY+COMM AS "TOTAL COMP"
  FROM EMP
  WHERE SALARY+COMM> 40000
  ORDER BY SALARY+COMM;

The result table looks like the following example:

EMPNO    SALARY     COMM      TOTAL COMP
======   ========   =======   ==========
000030   38250.00   3060.00   41310.00
000020   41250.00   3300.00   44550.00 
200010   46500.00   4220.00   50720.00
000010   52750.00   4220.00   56970.00
End general-use programming interface information.