在此处输入图像描述当插入与产品相关的付款金额时,我想更新"产品"中的"已付款"列。。。
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;
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/