“from在此位置无效”这是我在mysql工作台中使用updatejoin时遇到的语法错误

rdrgkggo  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(315)

在这里输入图像描述我想更新产品中的付款列时,付款金额得到插入有关产品。。。

create table Product(
PID INT primary key,
Paid int not null default 0 ,
Total int not null
);

create table payment(
paymentid int primary key,
productid int not null,
amount int not null,
foreign key (productid) references product(paid)
);

(I am just using the dummy table to practice update using join)

update product 
set product.paid=(pay.amount+pr.Paid)
from-----> here I am getting error
payment pay 
inner join product  pr on
pay.productid=pr.pid;
lxkprmvk

lxkprmvk1#

create table product(
PID INT primary key,
Paid int not null default 0 ,
Total int not null
);

create table payment(
paymentid int primary key,
productid int not null,
amount int not null,
foreign key (productid) references product(paid)
);
UPDATE
        product
    INNER JOIN payment ON product.PID = payment.productid
    SET
        product.Paid = (product.Total+payment.amount)
    WHERE
        product.PID = payment.productid

我测试它现在工作正常。我希望它对你有用。请告诉我。如果你还面临同样的问题。谢谢。更多细节。https://www.mysqltutorial.org/mysql-update-join/

相关问题