主键在你需要统计的表里面
以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