[英]MySQL- How to use alias with CASE statement
I want to display First Name, Salary, Tenure and Bonus based on tenure but I am getting this error:我想根据任期显示名字、薪水、任期和奖金,但我收到此错误:
"TENURE": invalid identifier “TENURE”:无效的标识符
This is my query:这是我的查询:
select
first_name as "First Name", Salary,
round((sysdate - to_date(hire_date))/365.25,2) as Tenure,
Salary*(
CASE
when Tenure between 0 and 10 then 0.05
when Tenure between 11 and 15 then 0.1
when Tenure between 16 and 20 then 0.15
when Tenure > 20 then 0.2
END) as Bonus
from employees;
Try this.尝试这个。
SELECT AA.first_name as "First Name", AA.Salary,
AA.Salary*(
CASE
when AA.Tenure between 0 and 10 then 0.05
when AA.Tenure between 11 and 15 then 0.1
when AA.Tenure between 16 and 20 then 0.15
when AA.Tenure > 20 then 0.2
END) as Bonus
FROM (select
first_name, Salary,
round((sysdate - to_date(hire_date))/365.25,2) as Tenure
from employees)) AA;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.