2014-09-30 60 views
0

這段代碼和它關聯的數據庫表正在另一個站點上使用,並且完美地工作。但是,當我在另一個網站上使用它時,我收到一個錯誤。 我檢查了表,並且列attribute_id確實存在。我的SQL查詢在'on子句'中給出未知列'bisns.attribute_id'

SELECT bisns.product_id, pd.products_name, COUNT(*) AS num_subscribers, p.products_type,GROUP_CONCAT(DISTINCT CONCAT_WS(':', IFNULL(bisns.attribute_id, 'attribute_id'), pov.products_options_values_name, IFNULL(pwas.quantity, 'quantity'), IFNULL(bisns.customer_id, 'customer_id'), bisns.name, bisns.email_address)) as attributes, COUNT(DISTINCT bisns.product_id) as product_count_distinct, COUNT(DISTINCT bisns.attribute_id) as attribute_count_distinct, COUNT(bisns.attribute_id) as attribute_count,p.products_quantity AS current_stock, cd.categories_name 
     FROM 
      " . TABLE_BACK_IN_STOCK_NOTIFICATION_SUBSCRIPTIONS . " bisns 
     LEFT JOIN 
      " . TABLE_PRODUCTS_DESCRIPTION . " pd 
     ON 
      (pd.products_id = bisns.product_id 
     AND 
      pd.language_id = '" . $_SESSION['languages_id'] . "') 
     LEFT JOIN 
      " . TABLE_PRODUCTS . " p 
     ON 
      p.products_id = pd.products_id 
     LEFT JOIN 
      " . TABLE_CATEGORIES_DESCRIPTION . " cd 
     ON 
      (p.master_categories_id = cd.categories_id 
     AND 
      cd.language_id = '" . $_SESSION['languages_id'] . "') 
     LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa 
     ON pa.products_attributes_id = bisns.attribute_id 
     LEFT JOIN " . TABLE_PRODUCTS_OPTIONS . " po 
     ON pa.options_id = po.products_options_id 
     LEFT JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov 
     ON pa.options_values_id = pov.products_options_values_id 
     LEFT JOIN " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas 
     ON pa.products_attributes_id = pwas.stock_attributes 
     WHERE 
      1 = 1 
     GROUP BY 
      bisns.product_id" 

任何人都可以想出爲什麼這個查詢會拋出一個錯誤,以及如何解決它,因爲它讓我跳動的原因。

回答

0

首先要做的是檢查大小寫是否有差異。根據設置的不同,MySQL將檢查或不檢查案例的完全匹配。

第二件事是在替換完成後打印上面的sql字符串的最終結果,以確保一切正常。

最後,您可以嘗試直接在MySQL Workbench中運行最終查詢,以查看可能的錯誤。

相關問題