简体   繁体   English

MySQL未知列在where子句中,但该列存在

[英]MySQL Unknown column in where clause but column exists

So it seems some people have had this problem before, but searching didn't turn up an answer for my case. 因此,似乎有些人以前曾遇到过此问题,但搜索并没有找到我的情况的答案。

I'm running 我在跑

 UPDATE ProdCosts SET PercentCost = ((ProdCosts.PieceCost/totalprodcost.sumpiececost)*100)
 WHERE totalprodcost.ProdNo=ProdCosts.ProdNo;
 AND ProdCosts.PieceCost > 0;

and getting the error 并得到错误

MySQL said: Documentation
#1054 - Unknown column 'totalprodcost.ProdNo' in 'where clause' 

DESCRIBE totalprodcost shows: DESCRIBE totalprodcost显示:

Field   Type    Null    Key     Default     Extra
ProdNo  int(11) YES         NULL    
sumpiececost    double  YES         NULL    

I can't figure this out. 我不知道这个。 It seems simple enough. 看起来很简单。 What gives? 是什么赋予了?

Join the tables on UPDATE statement, UPDATE语句上联接表,

UPDATE  ProdCosts a
        INNER JOIN totalprodcost b
            ON b.ProdNo = a.ProdNo
SET     a.PercentCost = ((a.PieceCost/b.sumpiececost)*100)
WHERE   a.PieceCost > 0;

Try this query 试试这个查询

UPDATE ProdCosts, totalprodcost SET ProdCosts.PercentCost = ((ProdCosts.PieceCost/totalprodcost.sumpiececost)*100) WHERE totalprodcost.ProdNo=ProdCosts.ProdNo AND ProdCosts.PieceCost > 0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM