SQL CASE in a clause ORDER BY


Example

We can use 1,2,3.. to determine the type of order:

SELECT * FROM DEPT
ORDER BY
CASE DEPARTMENT
      WHEN 'MARKETING' THEN  1
      WHEN 'SALES' THEN 2
      WHEN 'RESEARCH' THEN 3
      WHEN 'INNOVATION' THEN 4
      ELSE        5
      END,
      CITY
IDREGIONCITYDEPARTMENTEMPLOYEES_NUMBER
12New EnglandBostonMARKETING9
15WestSan FranciscoMARKETING12
9MidwestChicagoSALES8
14Mid-AtlanticNew YorkSALES12
5WestLos AngelesRESEARCH11
10Mid-AtlanticPhiladelphiaRESEARCH13
4MidwestChicagoINNOVATION11
2MidwestDetroitHUMAN RESOURCES9