gpt4 book ai didi

mysql - 如何使用从另一个表中选择的字段更新表?

转载 作者:行者123 更新时间:2023-11-30 23:37:21 25 4
gpt4 key购买 nike

虽然类似这样的问题还有很多,比如“Updating a record from another table ”,但我无法让它工作。

我有一个选择和更新表 sem_stdexamfinresmark 的查询。选择子查询返回多行数据,其大小可能不等于正在更新的表,但现在正在更新。

查询看起来像:

update  sem_stdexamfinresmark sr,
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession =1 and classid='8'
) s
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession = s.currsession and
sr.classid='8';

编辑:

update  sem_stdexamfinresmark 
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
from
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession = 1 and classid='8'
) s
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession =1 and
sr.classid='8';
select * from sem_exam;
update sem_exam set currsession =1;

最佳答案

尝试一些看起来更像的东西:

update foo
set col = bar.col
from bar
where ...

关于mysql - 如何使用从另一个表中选择的字段更新表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6406776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com