2012-03-01 29 views
0

嗨,我讓我的CONCATS語法錯誤出於某種原因, 這是因爲它幾乎複製/從另一個 使用作品完美CONCATS我查詢之一粘貼非常奇怪的?mysql的語法錯誤與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日期,」在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

,請複製粘貼錯誤消息。 – 2012-03-01 17:57:00

+0

剛把它粘貼上面 – ehime 2012-03-01 17:58:31

回答

4

CONCAT本身沒有問題,但case是MySQL中的一個保留字,需要反斜槓轉義。

+0

把case更改爲case_cnt後,我得到錯誤**你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在第18行**' – ehime 2012-03-01 18:00:22

+0

'附近'condition,rating,inspector AS insp,comments FROM lot'LIMIT 0'使用正確的語法。不幸的是,'condition'是另一個保留字。 @ Mchl的迴應鏈接到保留字的完整列表。 – 2012-03-01 18:02:35

+0

是的,就是這樣,似乎今天使用所有保留字= P – ehime 2012-03-01 18:04:30