【问题标题】:How do i change the result of an ORACLE select query for specific type of data?如何更改特定类型数据的 ORACLE 选择查询的结果?
【发布时间】:2020-04-12 17:28:15
【问题描述】:

我有一个名为 EMPLOYEES 的表,其中包含 EMPLOYEE_ID、NAME 和 DEPARTMENT_ID 列。我必须列出所有员工,如果部门 ID 为 10,则将属性 NAME 的输出更改为“---”。

我该怎么做?谢谢!

【问题讨论】:

    标签: sql oracle


    【解决方案1】:
    select 
        employee_id, 
        case when department_id = 10 then '---' else name end as name, 
        department_id
    from employees;
    

    【讨论】:

      【解决方案2】:

      使用union all的另一种解决方案

      select 
          employee_id, name,  department_id
      from employees WHERE department_id != 10
      UNION all
      select 
          employee_id, '---' name,  department_id
      from employees WHERE department_id = 10
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-24
        • 1970-01-01
        • 2017-09-23
        • 1970-01-01
        • 2012-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多