标签:
/*
触发器
触发器基本语法:
create trigger 触发器名称 [before/after] [insert/update/delete] on 表名
for each row
begin
触发器正文
end;
*/
示例一(仅供参考)
create trigger 触发器名称 after insert on 表名
for each row
BEGIN
DECLARE recIdNo int(11);
DECLARE rownum int(11);
DECLARE maxTemperaNo decimal(15,2);
DECLARE avgTempera decimal(15,2);
set rownum = (select count(*) from 表明 where DATE(date)= DATE(new.datetime));
-- 判断基本语法
if rownum > 0 then
-- 这两条语句是变量的赋值
select maxTempera into maxTemperaNo from (select * from t_data_temperahumidydefine_d where DATE(date) = DATE(new.datetime) order by date desc) as t_data_temperahumidydefine_h limit 1;
select avg(tempera) into avgTempera from t_data_temperahumidydefine_h where date(dateTime)=date(new.datetime);
IF new.tempera > maxTemperaNo THEN
set maxTemperaNo = new.tempera;
end IF;
-- 修改语句
update t_data_temperahumidydefine_d
set maxTempera = maxTemperaNo , avgTempera = avgTempera
where recId = recIdNo;
else
-- 执行插入语句
end if;
end;
标签:
原文地址:http://www.cnblogs.com/jingjie/p/4434842.html