update 表名 set 字段名= 为什么不能用聚合函数


update 
sc 
set score=avg(score) 
where 
sno='1911201' 
and cno='0000034';

聚合函数要放在查询里面才能用,当然你可以组合

你没有select,avg(score)是个什么呀

这个可以用子查询去做,where的优先级别高,过滤后的数据就不能avg了

update sc set score= (SELECT avg(score) FROM sc AS sc1 WHERE sc1.sno= sc2.sno and sc1.cno=sc2.cno ) from sc sc2
where sc2.sno='1911201' and sc2.cno='0000034

可以尝试使用这个sql,如有帮助望采纳


update 
sc 
set score=(select avg(score)from sc )
where 
sno='1911201' 
and cno='0000034';