我几分钟前发布了一个问题并得到了这个问题
update pf
set price_test = (p.PRICE * .6)
from product as p
inner join product_featured as pf on pf.product_id = p.product_id
Run Code Online (Sandbox Code Playgroud)
这是我的数据库结构
产品表
product_id int(11) NO PRI NULL auto_increment
model varchar(64) NO NULL
sku varchar(64) NO NULL
location varchar(128) NO NULL
quantity int(4) NO 0
stock_status_id int(11) NO NULL
image varchar(255) YES NULL
manufacturer_id int(11) NO NULL
shipping int(1) NO 1
price decimal(15,4) NO 0.0000
Run Code Online (Sandbox Code Playgroud)
product_featured表
product_id int(11) NO PRI 0
price_test decimal(15,2) YES NULL
Run Code Online (Sandbox Code Playgroud)
但这是我的错误
编辑..
我需要这个为SQL工作.....
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from product as p
inner join product_featured as pf on pf.product_id = p.product' at line 3
Run Code Online (Sandbox Code Playgroud)
试试这个.
update product_featured pf
set price_test = (
select p.PRICE * .6
from product p
where pf.product_id = p.product_id
)
Run Code Online (Sandbox Code Playgroud)