【发布时间】:2011-03-23 13:00:21
【问题描述】:
我想要的是在更新/插入表 x 时,将表 y 中的值增加 1
下面的示例,使用了一个选择语句,我不能将其用作我正在尝试更新的表中选择
DELIMITER $$
create trigger occupancy
after insert on tbl_attendence
for each row
begin
set @course_id = new.course_id;
set @attendence_date = new.attendence_date;
if new.reason = 1 then
update tbl_course_occupancy
set occupancy_number= (select occupancy_number
from tbl_course_occupancy
where course_id = @course_id
and occupancy_year = EXTRACT(year from @attendence_date) ) + 1
where course_id = @course_id
and occupancy_year = Extract(year from @attendence_date);
end if;
end$$
如有任何帮助,谢谢
【问题讨论】: