2013-05-31 58 views
0

下面是我試圖執行的查詢,並且拋出了1048 Column 'sub_order_id' cannot be null錯誤。所以我查了表,order_products_boxesorders_products表似乎有數據對sub_order_id='22861-1R',所以任何想法,爲什麼我仍然得到錯誤?mysql錯誤,列爲空

SELECT Upper(Ifnull(op.supplier_payment_method, ''))      AS 
     Payment_Method, 
     op.supplier_payment_date            AS 
     Payment_Date, 
     Date_format(Ifnull(op.supplier_payment_date, op.ship_date), '%M %Y') AS 
     Payment_Month, 
     'B&H'                AS 
     Farm, 
     op.sub_order_id              AS 
     Order_num, 
     Date_format(op.ship_date, '%b-%d-%Y')        AS 
     Ship_Date, 
     op.farm_credit              AS 
     Farm_Credit, 
     op.credit_memo              AS 
     Credit_Memo, 
     op.credit_description            AS 
     Credit_Description, 
     opb.boxes               AS 
     Box_Type, 
     Concat('$', Format(op.box_charge, 2))        AS 
     Box_Charge, 
     op.invoice_num              AS 
     Invoice_num, 
     Concat('$', Format(op.invoice_amt, 2))        AS 
     Invoice_Amt, 
     Concat('$', Format(op.total_invoice_amt, 2))       AS 
     Total_Invoice_Amt, 
     Concat(op.um_qty, ' ', op.um_type)         AS 
     St_Bu_Qty, 
     op.po_product_name             AS 
     Invoice_desc, 
     Concat('$', Format((op.price_um * op.um_qty), 2))     AS 
     Cost_product_cms, 
     op.supplier_invoice_note            AS 
     Supplier_Invoice_Notes, 
     Concat('$', Format(op.cms_invoice_cost, 2))       AS 
     CMS_Invoice_diff, 
     Concat('$', Format(op.total_farm_cost, 2))       AS 
     Farm_Cost 
FROM orders_products op 
     LEFT JOIN (SELECT sub_order_id, 
Group_concat(Concat(box_type_qty, ' ', bo.box_option_name) 
          SEPARATOR 
            ', ') AS 
boxes 
FROM order_products_boxes opb 
INNER JOIN box_options bo 
     ON bo.id = opb.box_type_id 
WHERE opb.sub_order_id = '22861-1R') opb 
ON opb.sub_order_id = op.sub_order_id 
WHERE op.sub_order_id = '22861-1R' 
ORDER BY op.ship_date DESC 
+0

是INSERT語句的一部分嗎? –

+0

不,這只是一個選擇查詢 – Bluemagica

+0

問題....如果您從查詢中刪除該字段....查詢的工作原理是如果?? – Hackerman

回答

0
Description: 
null values in selected columns for left side of join cause error: 
"1048 column 'name' cannot be null" 

因此猜測其行 ON opb.sub_order_id = op.sub_order_id

不喜歡whne op.sub_order_id是空在那裏後,加入測試

您可以嘗試:

ON opb.sub_order_id = COALESCE(op.sub_order_id, -1) 
+0

爲什麼連接左側的NULL值會導致錯誤? –

+0

不知道,只是發現解釋當我谷歌搜索,如果它的真實,你可以嘗試,看看如果行修復它 –

+0

你發現這個頁面? –