2015-12-16 56 views
0

我有一点点做大SQL查询,与它的问题SQL - 如果SQL语法语句抛出错误

错误,我得到:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po' at line 6 

QUERY我使用:

SELECT c.vin, c.case_id, c.claimnumber, c.platenumber, c.axrmrs_id, c.insurer_memberid, c.country, c.date_created, c.totalloss, c.lastcalc_manufacturer_code, c.lastcalc_model_code, c.lastcalc_submodel_code, c.audavin_triggered, c.accident_date, c.registration_date, c.manufacturing_year, 
         cl.spareparts, cl.totalcosts, cl.laborhours, cl.laborcosts, cl.calculationdate, cl.paintlabor, cl.paintmaterial, cl.currency, car.manufacturer, car.model, car.submodel, 
         IFNULL(org.name, 0) as orgName, 
         GROUP_CONCAT(DISTINCT IF(po.repairmethod LIKE 'L%',po.text,NULL) ORDER BY 1) AS textL, 
         GROUP_CONCAT(DISTINCT IF(po.repairmethod = 'E',po.text,NULL) ORDER BY 1) AS textE 
         GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po.guidenumber = 'N/A') AND po.repairmethod NOT LIKE 'L%',NULL) ORDER BY 1) AS textO 
        FROM axnmrs_cases AS c 
         LEFT JOIN axnmrs_calculations as cl on c.case_id = cl.case_id AND c.country = cl.country 
         LEFT JOIN axnmrs_positions as po on c.case_id = po.case_id 
         LEFT JOIN car_type as car on car.manufacturer_code = c.lastcalc_manufacturer_code AND car.main_type = c.lastcalc_model_code AND car.subtype_code = c.lastcalc_submodel_code 
         LEFT JOIN organization_list as org on org.memberId = c.insurer_memberid 
        WHERE c.vin= "U5YFF24128L064909" 
         GROUP BY c.vin, c.case_id, c.axrmrs_id 

我在想方括号中的问题,但我试图取而代之不幸没有成功。

整个查询工作不正确去年GROUP_CONCAT LINE(如错误已经说basicly)

任何提示什么是我做错了,或如何optimalizate此查询? 谢谢:)

编辑:添加逗号后 错误在第二GROUP_CONCAT结束:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY 1) AS textO FROM axnmrs_cases AS c ' at line 6 
+0

请添加相关标签。 'GROUP_CONCAT'不在sql server中,所以删除sql server标签 –

+0

对不起@KrishnrajRana,编辑它:) – Andurit

+0

你可能会在下一个GROUP_CONCAT之前的“AS textE”后面缺少一个逗号。 – BWS

回答

2

发现一个

在这种方式

GROUP_CONCAT(DISTINCT IF(po.repairmethod = 'E',po.text,NULL) ORDER BY 1) AS textE, 

在样品

GROUP_CONCAT(DISTINCT IF(po.repairmethod = 'E',po.text,NULL) ORDER BY 1) AS textE 

在此像的端mssing逗号并且还缺少一个参数第三的concat看到****missing****

GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po.guidenumber = 'N/A') 
AND po.repairmethod NOT LIKE 'L%',****missing ***,NULL) ORDER BY 1) AS textO 
+0

比我快... –

+0

嗨@scaisEdge,谢谢你。你是对的,但是这个我得到同样的错误只是在代码的另一部分,请检查我的编辑:) – Andurit

+0

我发现了另一个错误,并有更新答案 – scaisEdge

2

您在seccond GROUP_CONCAT后缺乏comma

SELECT c.vin, c.case_id, c.claimnumber, c.platenumber, c.axrmrs_id, c.insurer_memberid, c.country, c.date_created, c.totalloss, c.lastcalc_manufacturer_code, c.lastcalc_model_code, c.lastcalc_submodel_code, c.audavin_triggered, c.accident_date, c.registration_date, c.manufacturing_year, 
        cl.spareparts, cl.totalcosts, cl.laborhours, cl.laborcosts, cl.calculationdate, cl.paintlabor, cl.paintmaterial, cl.currency, car.manufacturer, car.model, car.submodel, 
        IFNULL(org.name, 0) as orgName, 
        GROUP_CONCAT(DISTINCT IF(po.repairmethod LIKE 'L%',po.text,NULL) ORDER BY 1) AS textL, 
        GROUP_CONCAT(DISTINCT IF(po.repairmethod = 'E',po.text,NULL) ORDER BY 1) AS textE , 
        GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po.guidenumber = 'N/A') AND po.repairmethod NOT LIKE 'L%',NULL) ORDER BY 1) AS textO 
       FROM axnmrs_cases AS c 
        LEFT JOIN axnmrs_calculations as cl on c.case_id = cl.case_id AND c.country = cl.country 
        LEFT JOIN axnmrs_positions as po on c.case_id = po.case_id 
        LEFT JOIN car_type as car on car.manufacturer_code = c.lastcalc_manufacturer_code AND car.main_type = c.lastcalc_model_code AND car.subtype_code = c.lastcalc_submodel_code 
        LEFT JOIN organization_list as org on org.memberId = c.insurer_memberid 
       WHERE c.vin= "U5YFF24128L064909" 
        GROUP BY c.vin, c.case_id, c.axrmrs_id 
+0

赶,我upvote你..相同的答案 – scaisEdge

+0

哎@Oscar佩雷斯,谢谢你。你是对的,但放弃这个事实它不工作:( 请检查我的编辑 – Andurit