2

所以似乎有些人以前遇到过这个问题,但是搜索并没有为我的案例找到答案。

我在跑

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

并得到错误

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

DESCRIBE totalprodcost 显示:

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

我想不通。看起来很简单。是什么赋予了?

4

2 回答 2

0

加入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;
于 2013-01-31T04:49:47.173 回答
0

试试这个查询

更新 ProdCosts, totalprodcost SET ProdCosts.PercentCost = ((ProdCosts.PieceCost/totalprodcost.sumpiececost)*100) 其中 totalprodcost.ProdNo=ProdCosts.ProdNo AND ProdCosts.PieceCost > 0;
于 2013-01-31T05:14:10.093 回答