我有一张表,其中有两列:薪水和新闻报道。我想用工资减去新闻工资并将其存储在新栏目中。我怎么能这样做?
这不起作用:
SELECT employee_id, last_name, salary, round((salary * 0.155 + salary)) AS newsal, SUBSTR(newsal, salary) AS Increase FROM employees;
这也不起作用
SELECT employee_id, last_name, salary, round((salary * 0.155 + salary)) AS newsal, sum(newsal - salary) AS Increase FROM employees;
答案 0 :(得分:1)
你不能在别名中使用别名作为列名,你必须重复代码和 只需使用减号
SELECT employee_id
, last_name
, salary
, round((salary * 0.155 + salary)) AS newsal
, ( round(salary * 0.155 + salary) -salary) AS Increase
FROM employees;
或者你可以使用subselect作为表
select employee_id
, last_name, salary
, (newsal - salary= AS Increase
from (
SELECT employee_id
, last_name
, salary
, round((salary * 0.155 + salary)) AS newsal
FROM employees
) t