Mysql错误,我没想到

时间:2010-09-25 12:46:21

标签: mysql

错误:

Unknown column 'miahrose_pos104.phppos_sales.item_id' in 'on clause'

我不认为这应该发生,因为我正在将phppos_sales_items加入到phppos_items中,但似乎查询认为它正在加入phppos_sales。我做错了什么?

查询:

CREATE TEMPORARY TABLE phppos_sales_items_temp 
(SELECT date(sale_time) as sale_date, phppos_sales_items.sale_id, comment,payment_type, customer_id, employee_id, phppos_items.item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent, discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(1+(SUM(percent)/100)),2) as total, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*(SUM(percent)/100),2) as tax, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit FROM ((((
phppos_sales_items 
INNER JOIN phppos_sales USING (sale_id)) 
INNER JOIN phppos_items USING (item_id)) 
LEFT OUTER JOIN phppos_suppliers ON phppos_items.supplier_id=phppos_suppliers.person_id) LEFT OUTER JOIN phppos_sales_items_taxes USING (sale_id, item_id)) 
GROUP BY sale_id, item_id)

1 个答案:

答案 0 :(得分:0)

  

我不认为这应该发生   因为我要加入   phppos_sales_items到phppos_items,   但似乎查询认为它是   加入phppos_sales。是什么   我做错了吗?

你自己比在MySQL RDBMS系统中更多地相信自己。

如果错误信息与珍惜的假设相矛盾,请相信该信息并检查您的假设。

这是一个相对冗长的查询,因此发生错误的可能性不为零。仔细检查你的代码,你会发现MySQL抱怨的是什么。

这不是问题吗?

phppos_sales_items 
INNER JOIN phppos_sales USING (sale_id)) 
INNER JOIN phppos_items USING (item_id))
  

我不认为这应该发生,因为我正在将phppos_sales_items加入到phppos_items中,但似乎查询认为它正在加入phppos_sales。

我对此声明感到困惑,因为它暗示不涉及phppos_sales,但这段代码清楚地表明它是。