三个表
表A是国家GDP汇总表,表B是省的GDP值,表C是国家和省份的关系表
现在我在表B中建触发器,当tb_b中省份GDP更新时,对应国家GDP的值增大或者减少。
怎么整?我遇到的问题是new row如何跟tb_c表关联?join还是怎么写?
tb_a
country_id
country_GDPtb_b
province_id
province_GDPtb_c
country_id
province_id
表A是国家GDP汇总表,表B是省的GDP值,表C是国家和省份的关系表
现在我在表B中建触发器,当tb_b中省份GDP更新时,对应国家GDP的值增大或者减少。
怎么整?我遇到的问题是new row如何跟tb_c表关联?join还是怎么写?
tb_a
country_id
country_GDPtb_b
province_id
province_GDPtb_c
country_id
province_id
tb_b中的触发器(用子查询)
begin
update tb_a set country_GDP=country_GDP-old.province_GDP+new.province_GDP where country_id=(select country_id from tb_c where province_id=old.province_id)
end
set tb_a.country_GDP=tb_acountry_GDP-old.province_GDP+new.province_GDP
where tb_a.country_id=tb_c.country_id
and tb_c.province_id=old.province_id
on tb_a.country_id=tb_c.country_id
and tb_c.province_id=old.province_id set tb_a.country_GDP=tb_acountry_GDP-old.province_GDP+new.province_GDP