2017-03-10 56 views
0

我不確定爲什麼我在第一個CASE關鍵字的每個單詞中出現錯誤,並且在我的MySQL查詢中,我希望有人可能會看到我一直在支付的東西我的腦子在過去的幾個小時裏反對。下面的代碼的修剪樣本:MySQL CASE語句無法識別的關鍵字和意外的令牌

CREATE TEMPORARY TABLE low_revenue_a ENGINE=MEMORY AS 
(SELECT fielda,fieldb, 
CASE WHEN quality_rev = 'A' THEN 1 WHEN quality_rev = 'B' THEN 2 WHEN quality_rev = 'C' THEN 3 END AS quality_rev, 
fieldc,fieldd, 
CASE WHEN quality_sales = 'A' THEN 1 WHEN quality_sales = 'B' THEN 2 WHEN quality_sales = 'C' THEN 3 END AS quality_sales, 
fielde,fieldf, 
CASE WHEN quality_other_sales = 'A' THEN 1 WHEN quality_other_sales = 'B' THEN 2 WHEN quality_other_sales = 'C' THEN 3 END AS quality_other_sales, 
fieldg,fieldh,myyear 
FROM Db.mytable 
WHERE myyear = 2014); 

一旦我添加了CASE聲明,所有的意外的標記和未確認關鍵字的錯誤出現。有任何想法嗎?

回答

1

這是否會產生相同的錯誤?

CREATE TEMPORARY TABLE low_revenue_a ENGINE=MEMORY AS 
    SELECT fielda, fieldb, 
      (CASE WHEN quality_rev = 'A' THEN 1 
       WHEN quality_rev = 'B' THEN 2 
       WHEN quality_rev = 'C' THEN 3 
      END) AS quality_rev, 
      fieldc, fieldd, 
      (CASE WHEN quality_sales = 'A' THEN 1 
       WHEN quality_sales = 'B' THEN 2 
       WHEN quality_sales = 'C' THEN 3 
      END) AS quality_sales, 
      fielde, fieldf, 
      (CASE WHEN quality_other_sales = 'A' THEN 1 
       WHEN quality_other_sales = 'B' THEN 2 
       WHEN quality_other_sales = 'C' THEN 3 
      END) AS quality_other_sales, 
      fieldg, fieldh, myyear 
    FROM Db.mytable 
    WHERE myyear = 2014; 
+0

我的問題是兩倍。一,括號確實幫助並消除了phpmyadmin中顯示的錯誤。另一個原因是我自己愚蠢的疏忽,因爲我拼錯了一個字段名:quality_rev。非常感謝!無論如何,你的建議確實對我收到的大量錯誤有用。 –