MySQL CASE语句无法识别的关键字&意外令牌

时间:2017-03-10 22:43:23

标签: mysql

我不确定为什么我的第一个CASE关键字中的每个单词都出现错误,并且在我的MySQL查询中也是如此,我希望有人可能会看到我一直在讨厌的问题。过去几个小时。这是代码的修剪样本:

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 个答案:

答案 0 :(得分: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;