我正在尝试对以下select语句运行更新,但我不认为mysql非常喜欢我的语法,请指教?
UPDATE `invoice_lines`
SET
`invoice_lines`.`cost_price` = Costnew,
`invoice_lines`.`list_price` = Listnew,
`invoice_lines`.`unit_price` = Unitnew
SELECT (quote_lines.`list_price` * products.commision_pers/100) AS Listnew,
(quote_lines.`cost_price` * products.commision_pers/100) AS Costnew,
(quote_lines.`unit_price` * products.commision_pers/100) AS Unitnew
FROM `quote_lines`
INNER JOIN quotes
ON quotes.id = quote_lines.`quote_id`
INNER JOIN QuotePers
ON quoteid = quotes.id
INNER JOIN products
ON products.id = quote_lines.`related_id`
INNER JOIN invoice
ON invoice.`from_quote_id` = QuotePers.quoteid
INNER JOIN invoice_lines
ON invoice_lines.`invoice_id` = invoice.id
WHERE products.id = invoice_lines.`related_id`
AND prodid = invoice_lines.related_id
AND invoice_id = invoice.id
GROUP BY quotes.id,products.`id`
答案 0 :(得分:0)
Buddy,尝试在where
条件下引用这些列的表名,并在下次使用table_name别名时使用这些大查询:)
UPDATE invoice_lines
SET
invoice_lines.cost_price = Costnew,
invoice_lines.list_price = Listnew,
invoice_lines.unit_price = Unitnew
SELECT (quote_lines.list_price * products.commision_pers/100) AS Listnew,
(quote_lines.cost_price * products.commision_pers/100) AS Costnew,
(quote_lines.unit_price * products.commision_pers/100) AS Unitnew
FROM quote_lines
INNER JOIN quotes
ON quotes.id = quote_lines.quote_id
INNER JOIN QuotePers
ON quote_lines.quoteid = quotes.id
INNER JOIN products
ON products.id = quote_lines.`related_id`
INNER JOIN invoice
ON invoice.from_quote_id = QuotePers.quoteid
INNER JOIN invoice_lines
ON invoice_lines.invoice_id = invoice.id
WHERE products.id = invoice_lines.related_id
AND quote_lines.prodid = invoice_lines.related_id
AND quote_lines.invoice_id = invoice.id
GROUP BY quotes.id,products.id
答案 1 :(得分:0)
试试这个,我无法测试它,因为我没有你的数据库架构:
UPDATE `invoice_lines`
INNER JOIN quotes
ON quotes.id = quote_lines.`quote_id`
INNER JOIN QuotePers
ON quoteid = quotes.id
INNER JOIN products
ON products.id = quote_lines.`related_id`
INNER JOIN invoice
ON invoice.`from_quote_id` = QuotePers.quoteid
INNER JOIN invoice_lines
ON invoice_lines.`invoice_id` = invoice.id
WHERE products.id = invoice_lines.`related_id`
AND prodid = invoice_lines.related_id
AND invoice_id = invoice.id
SET
`invoice_lines`.`cost_price` = (quote_lines.`cost_price` * products.commision_pers/100),
`invoice_lines`.`list_price` = (quote_lines.`list_price` * products.commision_pers/100),
`invoice_lines`.`unit_price` = (quote_lines.`unit_price` * products.commision_pers/100)
希望它能让你走上正轨。 另请查看此related question