主键在你需要统计的表里面以device_id,date,shift_id建立主键如果是统计总数,在记录表中建立触发器 create trigger tri_recond after insert on record for each row begin insert into(device_id,date,shift_id,count) values(NEW.device_id,NEW.date, NEW.shift_id, NEW.count) on duplicate key update count = count + NEW.count end
另外主键是建立在要插入的count表上吗? 表是不是要drop掉重新建?
只能统计所有日期的油耗?
主键在你需要统计的表里面以device_id,date,shift_id建立主键如果是统计总数,在记录表中建立触发器
create trigger tri_recond after insert on record for each row
begin
insert into(device_id,date,shift_id,count) values(NEW.device_id,NEW.date, NEW.shift_id, NEW.count)
on duplicate key update
count = count + NEW.count
end