PSQL(9.6.1,9.5.5服務器)如何不在選擇中計算兩次值?
員工
Column | Type | Modifiers | Storage | Stats target | Description
----------------+-----------------------------+-----------------------------------------------------------------+----------+--------------+---- ---------
employee_id | integer | not null default nextval('employees_employee_id_seq'::regclass) | plain | |
first_name | character varying(20) | | extended | |
last_name | character varying(25) | not null | extended | |
email | character varying(25) | not null | extended | |
phone_number | character varying(20) | | extended | |
hire_date | timestamp without time zone | not null | plain | |
job_id | character varying(10) | not null | extended | |
salary | numeric(8,2) | | main | |
commission_pct | numeric(2,2) | | main | |
manager_id | integer | | plain | |
department_id | integer
我需要提取員工編號,姓氏,薪金,工資增加了15.5%(表示爲一個整數),以及新舊工資的差額。
我做這樣的:
select employee_id,
last_name,
salary,
round(salary * 1.155, 0) as "New Salary",
round(salary * 1.155, 0) - salary as "Increase"
from employees;
什麼困擾我的是,我已經計算出新的工資的兩倍。
我試圖在同一選擇中使用別名。這樣做的實驗:
select 2 as val_a, val_a - 4; --not working
那麼,我的解決方案輸出可以接受的結果。但是沒有更好的解決方案嗎?
如果你擔心表現,那麼不要這樣。 –