如何使用oracle数值函数对列中的值进行分类

How to use oracle numeric functions to categorize values in column

我有一个 table Employee 有 2 列 Emp_NameEmp_Salary。我想检索 Emp_Name 和一个新列作为 Indicator,它为 Emp_Salary 生成 1 值大于 10000,否则生成 -1。

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

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

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

您可以在查询中使用 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