Tuesday, July 14, 2015

Order By Case


This is a simple example of using CASE to get a specific order in your output.
SELECT ename
     , job
  FROM scott.emp
ORDER BY CASE job
               WHEN 'PRESIDENT' THEN 1
               WHEN 'MANAGER'   THEN 2
               WHEN 'ANALYST'   THEN 3
               WHEN 'SALESMAN'  THEN 4
                                ELSE 5
          END
;

No comments:

Post a Comment