This is my update query:
update grade
set grade='A'
where (select assignment*0.3+midExam*0.35+finalExam*0.35 as FINALSCORE
from taking) >= 85
and taking.student_id = grade.student_id
and taking.subject_id = grade.subject-id;
and the result is below
Unknown column 'taking.student_id' in 'where clause'
What am i doing wrong?
The table taking
is inside a subquery then is not visible outside the subquery
for your need you should use an update with join
update grade
INNER JOIN taking ON taking.student_id=grade.student_id
and taking.subject_id=grade.subject_id
and taking.assignment*0.3+taking.midExam*0.35+taking.finalExam*0.35 >= 85
set grade='A'
for a general solution
you could try adding a case when for each grade
update grade
INNER JOIN taking ON taking.student_id=grade.student_id
and taking.subject_id=grade.subject_id
set grade = (case when taking.assignment*0.3+taking.midExam*0.35+taking.finalExam*0.35 >= 85 THEN 'A'
when taking.assignment*0.3+taking.midExam*0.35+taking.finalExam*0.35 between 60.0 and 84.9 THEN 'B'
ELSE 'C' END)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.