where子句中的列'product_code'是不明确的

时间:2017-09-14 12:32:34

标签: mysql

    SELECT rm_item_cost.product_code, SUM(rm_item_cost.cost) AS rm_cost, SUM(dm_item_cost.cost) AS dm_cost, SUM(labour_item_cost.cost) AS labour_cost, SUM(overheads_item_cost.cost) AS o_cost 
FROM rm_item_cost 
INNER JOIN dm_item_cost ON dm_item_cost.product_code = rm_item_cost.product_code 
INNER JOIN labour_item_cost ON labour_item_cost.product_code = dm_item_cost.product_code 
INNER JOIN overheads_item_cost ON overheads_item_cost.product_code = labour_item_cost.product_code 
WHERE product_code = 'CMRO-01'

1 个答案:

答案 0 :(得分:2)

在您选择的表中,您有一个名为product_code的列,因此您必须添加一个别名来告诉mysql您指的是哪个列:

WHERE rm_item_cost.product_code = 'CMRO-01'