在 Oracle 的 Where 子句中使用 Case 语句 SQL
Using Case statement in Where clause in Oracle SQL
我有一个 select 语句如下
select *
from employees
where emp_id <= v_emp_id;
如果国家不是美国,我希望这个 emp_id
是 <= v_emp_id
。
如果国家是美国,那么我希望 emp_id
是 = v_usa_emp_id
。
你的问题有点模棱两可。我假设 country
是 table employees
数据类型 VARCHAR
中的一个属性。
SELECT * FROM employees
WHERE
(emp_id = v_emp_id AND country = 'USA')
OR (emp_id <= v_emp_id AND country != 'USA')
引用上面链接的 OR
页面:
If you use multiple logical operators in a statement, Oracle evaluates the OR operators after the NOT and AND operators. However, you can change the order of evaluation by using parentheses.
我有一个 select 语句如下
select *
from employees
where emp_id <= v_emp_id;
如果国家不是美国,我希望这个 emp_id
是 <= v_emp_id
。
如果国家是美国,那么我希望 emp_id
是 = v_usa_emp_id
。
你的问题有点模棱两可。我假设 country
是 table employees
数据类型 VARCHAR
中的一个属性。
SELECT * FROM employees
WHERE
(emp_id = v_emp_id AND country = 'USA')
OR (emp_id <= v_emp_id AND country != 'USA')
引用上面链接的 OR
页面:
If you use multiple logical operators in a statement, Oracle evaluates the OR operators after the NOT and AND operators. However, you can change the order of evaluation by using parentheses.