update更新数据的时候是在哪里连接两张表

现在有students表和sc表,ssex信息在students表中


update 
sc
set score=score*1.05 
where score<avg(score) and ssex='女';

改用MERGE 进行更新

假设是mysql
分析
1、update 涉及到2个表
2、实际更新的是sc 成绩表
3、过滤条件是 性别为女,且成绩小于平均成绩

实现
1、平均成绩
这个你得用子查询 select avg(score) from sc
2、关联更新
update student,sc -- 更新涉及2张表
set sc.score=sc.score*10.5 -- 更新sc表
-- 后面要做过2个表的关联了
where sc.sno = student.snoi -- 学号相同
and student.ssex='女’ -- 性别
and sc.score<(select avg(score) from sc) -- 这里得用子查询

看看如上的逻辑,应该没问题了

要是其它数据库,可以2个子查询
update sc
set sc.score=sc.score*1.05
where sc.score < (select avg(score) from sc) -- 成绩
and sc.sno in ( -- 学号
select sno from student where ssex='女‘
)

update students st,sc set sc.score = sc.score*1.05 where sc.score<avg( sc.score) and st.ssex='女' and st.id =sc.student_id;