• 在case表达式中使用单列子查询

    案例:

    需求:
    显式员工的employee_id,last_name和location。其中,若员工department_id与location_id为1800的department_id相同,则location为’Canada’,其余则为’USA’。
    1. SELECT employee_id,last_name,
    2. CASE department_id
    3. WHEN (SELECT department_id FROM departments WHERE location_id = 1800)
    4. THEN 'Canada'
    5. ELSE 'USA'
    6. END "location"
    7. FROM employees;