INSERT INTO data_prediction_model
select *, (
CASE WHEN ( offer_category like 'Everyday Low Prices on Receipe%'
OR offer_category like 'Every Day Low Prices%'
) THEN "EDLP"
ELSE
CASE WHEN (offer_category like 'Buy More & Save More%'
OR offer_category like 'Buy and Get Free'
) THEN "B1G1"
ELSE
CASE WHEN (offer_category like 'Offer on Activation/Qualification%'
OR offer_category like 'Save on Purchase of select Products/Plans%'
OR offer_category like 'Coupons Offers%'
OR offer_category like 'Digital Coupons Offers%'
OR offer_category like 'Discounted Products%'
OR offer_category like 'Exchange Offers%'
OR offer_category like 'Multiple Brand Offers%'
OR offer_category like 'Free with Rebate'
) THEN "Discounts"
END END END) AS offer_category
FROM data_offer;
答案 0 :(得分:0)
从你说的sql查询中,我假设你的CASE
语句错误
INSERT INTO data_prediction_model
select *, (
CASE WHEN ( offer_category like 'Everyday Low Prices on Receipe%' OR
offer_category like 'Every Day Low Prices%' )
THEN "EDLP"
WHEN (offer_category like 'Buy More & Save More%' OR
offer_category like 'Buy and Get Free')
THEN "B1G1"
WHEN (offer_category like 'Offer on Activation/Qualification%' OR
offer_category like 'Save on Purchase of select Products/Plans%' OR
offer_category like 'Coupons Offers%' OR
offer_category like 'Digital Coupons Offers%' OR
offer_category like 'Discounted Products%' OR
offer_category like 'Exchange Offers%' OR
offer_category like 'Multiple Brand Offers%' OR
offer_category like 'Free with Rebate' )
THEN "Discounts"
END) AS offer_category
FROM data_offer;
正确的CASE声明顺序, 应该像这样的模式
CASE
WHEN condition 1 THEN value 1
WHEN condition 2 THEN value 2
ELSE value 3
END
而不是你做的模式,看起来像这样
CASE
WHEN condition 1 THEN value 1
ELSE CASE
WHEN condition 2 THEN value 2
END
END
希望对你有所帮助。
答案 1 :(得分:0)
1136错误与表和插入中的列不匹配有关。
例如:
mysql> create table test (id int, name varchar(20));
Query OK, 0 rows affected (0.13 sec)
mysql> insert into test values (1, 'test', 'hello');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
请注意,以'hello'
的形式提供附加值会引发1136错误。表有2列。提供正确数据类型的2个值将成功:
mysql> insert into test values (1, 'test');
Query OK, 1 row affected (0.03 sec)
仔细检查data_prediction_model中的列计数与data_offer + case语句中的列计数相同。 Case语句创建一个新的插入字段。
编辑:
要解决此问题,请列出data_prediction_model中的所有列。列出data_offer中的所有列。 data_offer应该比data_prediction_model少1列。