oracle case when 使用方式
时间: 2024-02-05 09:03:55 浏览: 84
Oracle的CASE WHEN语句是一种条件表达式,用于根据不同的条件执行不同的操作。它的基本语法如下:
```
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
ELSE result
END
```
其中,condition1、condition2等是条件表达式,result1、result2等是对应条件为真时的结果。ELSE子句是可选的,用于指定当所有条件都不满足时的默认结果。
下面是一个示例,演示了如何使用CASE WHEN语句:
```
SELECT
employee_id,
first_name,
last_name,
CASE
WHEN salary > 5000 THEN 'High'
WHEN salary > 3000 THEN 'Medium'
ELSE 'Low'
END AS salary_level
FROM
employees;
```
在上面的示例中,根据员工的薪水将其分为三个级别:高、中、低。根据不同的薪水范围,使用CASE WHEN语句给出相应的级别。
相关问题
oracle case when使用
ORACLE中的CASE WHEN是一种条件表达式,可用于在SELECT语句中返回不同的结果,具体语法如下:
```
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
ELSE resultN
END
```
其中,condition1、condition2等是要检查的条件;result1、result2等是与每个条件相关的结果;ELSE子句是在所有条件都不满足时返回的结果。
例如,以下示例查询根据员工的工资级别返回不同的奖金:
```
SELECT last_name, salary,
CASE
WHEN salary >= 10000 THEN salary * 0.2
WHEN salary >= 5000 THEN salary * 0.1
ELSE salary * 0.05
END AS bonus
FROM employees;
```
以上查询将根据员工的工资级别返回不同的奖金,并将结果作为名为bonus的新列返回。
ORACLE CASE WHEN使用
ORACLE中的CASE WHEN是一种条件表达式,可用于在SELECT语句中返回不同的结果,具体语法如下:
```
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
ELSE resultN
END
```
其中,condition1、condition2等是要检查的条件;result1、result2等是与每个条件相关的结果;ELSE子句是在所有条件都不满足时返回的结果。
例如,以下示例查询根据员工的工资级别返回不同的奖金:
```
SELECT last_name, salary,
CASE
WHEN salary >= 10000 THEN salary * 0.2
WHEN salary >= 5000 THEN salary * 0.1
ELSE salary * 0.05
END AS bonus
FROM employees;
```
以上查询将根据员工的工资级别返回不同的奖金,并将结果作为名为bonus的新列返回。
阅读全文
相关推荐
















