2010-09-25 49 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