SELECT
employees.emp_id,
employees.emp_name_en,
employees.emp_name_ar,
employees.emp_nike_name,
employees.emp_basic_salary,
employees.emp_aw_food,
employees.emp_aw_car,
employees.emp_aw_mobile,
employees.emp_aw_trans,
employees.emp_aw_housing,
((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS insurance_ratio,
(((((`employees`.`emp_aw_housing` + `employees`.`emp_aw_trans`) + `employees`.`emp_aw_mobile`) + `employees`.`emp_aw_car`) + `employees`.`emp_aw_food`) + `employees`.`emp_basic_salary`) - ((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS net_salary,
(net_salary / 30 ) AS day_salary
FROM
employees ,
settings
WHERE
settings.set_key = 'insurance_ratio'
[Err] 1054 - “字段列表”中的未知列'net_salary'
我如何使用列'net_salary'
答案 0 :(得分:2)
但你能做些什么......
SELECT tab1.*, (tab1.net_salary / 30 ) AS day_salary
FROM (SELECT
employees.emp_id,
employees.emp_name_en,
employees.emp_name_ar,
employees.emp_nike_name,
employees.emp_basic_salary,
employees.emp_aw_food,
employees.emp_aw_car,
employees.emp_aw_mobile,
employees.emp_aw_trans,
employees.emp_aw_housing,
((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS insurance_ratio,
(((((`employees`.`emp_aw_housing` + `employees`.`emp_aw_trans`) + `employees`.`emp_aw_mobile`) + `employees`.`emp_aw_car`) + `employees`.`emp_aw_food`) + `employees`.`emp_basic_salary`) - ((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS net_salary
FROM
employees ,
settings
WHERE
settings.set_key = 'insurance_ratio') AS tab1
答案 1 :(得分:1)
是的,对于需要重复使用的大量计算列来说,这是一个众所周知的痛苦。
select emp_id,emp_name_en,emp_name_ar,emp_nike_name,emp_basic_salary,
emp_aw_food,emp_aw_car,emp_aw_mobile,emp_aw_trans,emp_aw_housing,
(net_salary / 30 ) AS day_salary
FROM
( SELECT
employees.emp_id,
employees.emp_name_en,
employees.emp_name_ar,
employees.emp_nike_name,
employees.emp_basic_salary,
employees.emp_aw_food,
employees.emp_aw_car,
employees.emp_aw_mobile,
employees.emp_aw_trans,
employees.emp_aw_housing,
((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS insurance_ratio,
(((((`employees`.`emp_aw_housing` + `employees`.`emp_aw_trans`) + `employees`.`emp_aw_mobile`) + `employees`.`emp_aw_car`) + `employees`.`emp_aw_food`) + `employees`.`emp_basic_salary`) - ((`settings`.`set_value` * `employees`.`emp_basic_salary`) / 100) AS net_salary
FROM
employees ,
settings
WHERE
settings.set_key = 'insurance_ratio'
) d;