我有更新查询:
UPDATE cash_billings_bills_articles
SET cash_billings_bills_articles.cashbillingbillarticle_cost = (SELECT articles_pricehistory.articlepricehistory_cost
FROM articles_pricehistory
LEFT JOIN cash_billings_bills
ON cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id
WHERE articles_pricehistory.article_id = cash_billings_bills_articles.article_id AND
articles_pricehistory.articlepricehistory_date <= cash_billings_bills.cashbillingbill_date
ORDER BY articles_pricehistory.articlepricehistory_date DESC
LIMIT 1
);
但是我得到了错误:Error Code: 1054. Unknown column 'cash_billings_bills_articles.cashbillingbill_id' in 'on clauseError Code: 1054. Unknown column 'cash_billings_bills_articles.cashbillingbill_id' in 'on clause' 0.000 sec
更新表格结构:
答案 0 :(得分:0)
您的加入条件似乎是错误的。在您的查询中,您尝试在条件
的情况下加入表格articles_pricehistory
和cash_billings_bills
cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id
其中cash_billings_bills.cashbillingbill_id
列应与articles_pricehistory
表而不是cash_billings_bills_articles
表的某些列进行比较。
您的查询应该更像
UPDATE cash_billings_bills_articles
SET
cash_billings_bills_articles.cashbillingbillarticle_cost = (SELECT
articles_pricehistory.articlepricehistory_cost
FROM
articles_pricehistory
LEFT JOIN
cash_billings_bills_articles ON cash_billings_bills_articles.article_id = articles_pricehistory.article_id
LEFT JOIN
cash_billings_bills ON cash_billings_bills_articles.cashbillingbill_id = cash_billings_bills.cashbillingbill_id
WHERE
articles_pricehistory.articlepricehistory_date <= cash_billings_bills.cashbillingbill_date
ORDER BY articles_pricehistory.articlepricehistory_date DESC
LIMIT 1)