Ahmed Mohamed Ahmed Mohamed - 2 months ago 6
MySQL Question

Mysql Can't use AS in query

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 - Unknown column 'net_salary' in 'field list'

how i can use column 'net_salary'

Answer

But what you could do...

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