2010-09-25 46 views
0

错误: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) 

回答

0

I don't think this should happen because I am joining phppos_sales_items to phppos_items, but it seems the query thinks it is being joined to phppos_sales. What am I doing wrong?

你更相信自己比你在MySQL RDBMS系统做的。

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

这是一个比较罗嗦的查询,所以发生错误的几率不为零。仔细检查你的代码,你会发现MySQL在抱怨什么。

这不是问题吗?

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

I don't think this should happen because I am joining phppos_sales_items to phppos_items, but it seems the query thinks it is being joined to phppos_sales.

我很困惑这个说法,因为这意味着phppos_sales不参与,但这个片段清楚地表明,它是。

+0

虽然这样做有什么问题,但它在mysql 5中正常工作,在mysql 4中失败。phppos_sales_items有一个sale_id和item_id – 2010-09-25 13:21:23

+0

然后,版本4和版本5中的数据库并不相同。或者在MySQL和版本4和5之间更改了某些内容,这些查询在新版本中是非法的。 – duffymo 2010-09-25 13:51:31

+0

看起来USING子句的某些地方改变了尝试加入到上一个表的位置。有谁知道USING子句是否改变了? – 2010-09-25 14:15:37