[英]Oracle SQL- Update Query with Case Statement Missing Keyword Error
[英]Oracle Sql query missing keyword error
我正在尝试这个查询
select
employee_id
,first_name
,last_name
, case
salary when(( commission_pct > 0) AND (commission_pct <= 0.15))
then salary*20/100
when commission_pct > 0.15
then salary*25/100
else 0
end INCENTIVE_AMT
from employees
order by employee_id;
但显示缺少关键字错误
我在“ commission_pct> 0”点收到此错误。
请帮我
别名在单词end
之后出现。
select case when this then that
else somethingelse end aliasName
你有这个:
select case when this then that aliasName
else something else aliasName end
就语法而言,这应该可以:
select employee_id,
first_name,
last_name,
case when commision_pct > 0 and commision_pct <= 0.15 then salary * 20 / 100
when commision_pct < 0.15 then salary * 25 / 100
else 0
end incentive_amt
from employees
order by employee_id;
但是,这没有多大意义-前两个CASE条件几乎相同-请注意,
when commision_pct <= 0.15
when commision_pct < 0.15
我说你必须改变它。
[编辑:关键字不遗漏]
我创建了一个虚拟的 EMPLOYEES表,以使查询不会失败。 然后我运行它-如您所见,一切都很好。 我建议您执行相同的操作-在SQL * Plus会话中发布CREATE TABLE
和SELECT
,以便我们可以看到您的工作以及Oracle的响应方式。
SQL> create table employees
2 (employee_id number,
3 first_name varchar2(20),
4 last_name varchar2(20),
5 commision_pct number,
6 salary number
7 );
Table created.
SQL> select employee_id,
2 first_name,
3 last_name,
4 case when commision_pct > 0 and commision_pct <= 0.15 then salary * 20 / 100
5 when commision_pct < 0.15 then salary * 25 / 100
6 else 0
7 end incentive_amt
8 from employees
9 order by employee_id;
no rows selected
SQL>
这是您的查询:
select
employee_id,
first_name,
last_name,
case
when COMMISSION_PCT > 0 AND COMMISSION_PCT <= 0.15
then salary*20/100
when commission_pct < 0.15
then salary*25/100
else 0
end INCENTIVE_AMT
from employees
order by employee_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.