嘿伙计们因为某些原因我的CONCATS上出现语法错误, 这非常奇怪,因为它几乎是来自另一个的复制/粘贴 我使用CONCATS的一个查询是否完美无缺?
这是错误的查询
SELECT
brand,
case_count AS case,
variety,
style,
grower_lot AS lot,
pack_date AS date,
CONCAT(berry_size1, "-", berry_size2, "/", berry_size3, "-", berry_size4) AS size,
CONCAT(color1, "-", color2) AS color,
CONCAT(stem1, "-", stem2, "-", stem3) AS stem_cndt,
CONCAT(bunch_count1, "-", bunch_count2, "-", bunch_count3) AS bnch_cnt,
CONCAT(shatter1, "-", shatter2) AS shatter,
CONCAT(splits1, "-", splits2) AS split,
CONCAT(decay_count1, "-", decay_count2) AS decay,
CONCAT(wet_sticky1, "-", wet_sticky2) AS wet_sticky,
overall_quality AS quality,
CONCAT(sugar_brix1, "-", sugar_brix2) brix,
overall_condition AS condition,
rating,
inspector AS insp,
comments
FROM `lot`
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在“案例,种类,风格,grower_lot AS批次,pack_date AS日期”附近使用正确的语法,在第3行
这是一个似乎有效的方法
SELECT
shipper,
po,
commodity as comm,
count,
size,
label,
variety,
pack_date AS date,
grower_lot AS lot,
CONCAT(color1, "-", color2) AS color,
CONCAT(sizing1, "-", sizing2, " / ", "sizing3", "-", sizing4 ) AS size,
CONCAT(firmness1, "-", firmness2) AS firmness,
CONCAT(scars_count1, "-", scars_count2) AS scars,
CONCAT(bruise_count2, "-", bruise_count2) AS bruise,
CONCAT(decay_count1, "-", decay_count2) AS decay_cnt,
CONCAT(sugar_brix1, "-", sugar_brix2) brix,
rating,
inspector AS insp,
comments
FROM `berries`
答案 0 :(得分:4)
CONCAT
本身不是问题,但case
是MySQL中的保留字,需要进行反向转义。
答案 1 :(得分:1)
case
是MySQL的保留字。如果要将其用作列别名,则需要将其放在反引号中。
此处提供的保留字的完整列表:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html