【问题标题】:How to use oracle numeric functions to categorize values in column如何使用 oracle 数值函数对列中的值进行分类
【发布时间】:2021-07-07 02:32:32
【问题描述】:

我有一个 Employee 表,其中包含 Emp_NameEmp_Salary 两列。我想检索 Emp_Name 和一个新列作为 Indicator,如果 Emp_Salary 值大于 10000,它会生成 1,否则生成 -1。

谁能告诉我在 Oracle 中的 SQL 查询。

【问题讨论】:

    标签: sql oracle-sqldeveloper


    【解决方案1】:

    一个 CASE 子句应该能够做到这一点:

    select emp_name, 
           case  when emp_salary > 10000 then 1 else -1 end salary_flag
    from employee
    

    【讨论】:

    • 非常感谢。
    • 这是第一个答案,它使用正确的标准 SQL 语法,因此看起来值得一票。
    【解决方案2】:

    您可以在查询中使用 CASE 或 IFF。两者都对你有用。以下是两个子句的代码

    Select Emp_Name, Emp_Salary, Case when Emp_Salary > 10000 then 1 else -1 end as Indicator 
    from Employee
    

    Select Emp_Name, Emp_Salary IIF (Emp_Salary > 10000 then 1 else -1) as Indicator
    from Employee
    

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 2019-11-25
    • 2019-10-11
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多