select t1.grade as "学生分数", t2.grade as "班级分数" from tb_student t0 join tb_student_grade t1 on t0.id = t1.student_id join tb_class_grade t2 on t0.class_id = t2.class_id where t0.`name` ='张三';
那么此时,我们只需要做一点小小的改动,就可以把上述sql改为连表update的了。
将select 字段... from 改为update
在where条件前写上自己,需要更新的字段
简单两步,改动结果后的sql如下
1 2 3 4 5 6
update tb_student t0 join tb_student_grade t1 on t0.id = t1.student_id join tb_class_grade t2 on t0.class_id = t2.class_id set t1.grade = t1.grade -10, t2.grade = t2.grade -10 where t0.`name` ='张三';