如何使用语句更新来更新mysql表?

时间:2012-11-11 17:44:42

标签: mysql join sql-update mysql-workbench

我需要更新注册表,并在课程表中为所有参加课程名称为“课程名称”的客户提供适当的费用

update from enrollment as e
    join course as c on c.coursenumber = e.coursenumber
    join customer as cs on cs.customernumber = e.customernumber 
set e.amountpaid = course.fee
where e.coursenumber in (select coursenumber from course where course = 'COURSE   NAME');

这可能在mysql中吗?我对这个DBMS和sql很新。

1 个答案:

答案 0 :(得分:0)

只需删除FROM关键字。

update enrollment as e
    join course as c on c.coursenumber = e.coursenumber
    join customer as cs on cs.customernumber = e.customernumber 
set e.amountpaid = course.fee
where e.coursenumber in (select coursenumber from course where course = 'COURSE   NAME');

或直接不用IN

update enrollment as e
    join course as c on c.coursenumber = e.coursenumber
    join customer as cs on cs.customernumber = e.customernumber 
set e.amountpaid = course.fee
where  c.course = 'COURSE   NAME';