我的数据库中有这些表:
employee
(emp_id
,emp_name
,dept_id
,type_of_work
,hourly_rate
)department
(dept_id
,dept_name
,dept_location
)address
(emp_id,street_no
,street_name
,city
,zip_code
)project
(project_id
,project_name
,project_location
)ft_pt_work
(project_id ,
emp_id,dept_id ,
num_of_hours ,
works_date`)salary
(emp_id
,basic
,net_salary, salary_date
)这里:
type_of_work
定义了就业类型(例如,全职/兼职,输入应为“ F / P”)net_salary
=基本+((1.0)+(0.45)+(-0.09)+(-0.15))对于兼职员工,basic = hourly_rate * num_of_hours
为了从基础上计算net_salary,我做了这个触发器,它在薪水表中产生了全职员工的net_salary:
DELIMITER $$
CREATE TRIGGER salary_bi
BEFORE INSERT ON salary
FOR EACH ROW
BEGIN
SET NEW.net_salary := NEW.basic * ( (1.0) + (0.45) + (-0.09) + (-0.15) );
END$$
DELIMITER ;
在那之后,我在下面做了第二个触发器来计算兼职员工的基本工资然后是net_salary ,但是却获得了basic和net_salary列为NULL!我该如何纠正?
我的代码:
DELIMITER $$
CREATE TRIGGER basic_pt_employees
BEFORE INSERT ON salary
FOR EACH ROW
BEGIN
IF (SELECT COUNT(*) FROM employee,ft_pt_work WHERE employee.type_of_work='P' AND employee.emp_id=NEW.emp_id) > 0 THEN
SET NEW.basic := employee.hourly_rate * ft_pt_work.num_of_hours;
END IF;
END$$