2 neil1225 neil1225 于 2016.05.11 17:08 提问

sql语句报错怎么修改呀!

sql语句为什么会报错!
String sql="select A.TIME,'销售出库' as XSTYPE,sum(A.NUMBER) AS NUMBER,sum(A.TOTAL) AS TOTAL,"
+"CASE F.PRODLEVEL WHEN '1' THEN '原厂' WHEN '2' THEN '正厂' WHEN '3' THEN '副厂' WHEN '4' THEN '品牌' WHEN '5' THEN '拆车件' END AS PRODLEVEL,"
+" CONCAT(I.className,'->',H.className,'->',G.className) as CLASSNAME,F.NO,F.PRODNAME,F.OENO"
+"FROM "
+"(select A.TIME,A.ID,'销售出库' as XSTYPE,B.NUM AS NUMBER ,B.PRICE AS D_PRICE,B.TOTAL AS TOTAL,B.PRODUCTS_ID AS P_WARES_ID,A.USER_ID,A.STORAGE_ID AS D_STORAGE,B.LOCATION_ID,A.TYPE AS P_TYPE,A.AUDIT_STATUS,A.COMPANY_ID,"
+" from jxc_t_outbound_info A"
+" left join jxc_t_outbound_detailed B on A.ID=B.OUTBOUND_ID"
+" UNION"
+" select C.TIME,C.ID,'销售退货' as XSTYPE,D.NUM AS NUMBER,D.PRICE AS D_PRICE,D.NUM*D.PRICE AS TOTAL,"
+" D.PRODUCTS_ID AS P_WARES_ID,C.USER_ID,C.STORAGE_ID AS D_STORAGE_ID,D.LOCATION_ID,'1' AS P_TYPE,C.AUDIT_STATUS,C.COMPANY_ID"
+" from jxc_t_outbound_revise C"
+"left join jxc_t_outbound_revise_detailed D on C.ID=D.OUTBOUND_REVISE_ID"
+") A"
+" left join jxc_t_products F on A.P_WARES_ID=F.ID"
+" left join jxc_t_providers C on A.USER_ID=C.ID"
+" left join shopping_goodsclass G on G.ID=F.GOODSCLASS_ID"
+"left join shopping_goodsclass H on H.ID=G.parent_id"
+"left join shopping_goodsclass I on I.ID=H.parent_id"
+" where A.P_TYPE='1' and A.AUDIT_STATUS='3'";
报错提示:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'select A.TIME,A.ID,'销售出库' as XSTYPE,B.NUM AS NUMBER ,B.PRICE AS D_PRICE,' at line 1;怎么解决呀!

5个回答

CSDNXIAON
CSDNXIAON   2016.05.11 17:12

SQL语句报错(一)
可以捕获报错的sql语句的触发器
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

u013782830
u013782830   2016.05.11 17:28

提示语法错误,好好看看SQl的语法吧

u011624972
u011624972   2016.05.11 17:33

把sql拆分,试试哪了语法错了。
1片段:
select A.TIME,A.ID,'销售出库' as XSTYPE,B.NUM AS NUMBER ,B.PRICE AS D_PRICE,B.TOTAL AS TOTAL,B.PRODUCTS_ID AS P_WARES_ID,A.USER_ID,A.STORAGE_ID AS D_STORAGE,B.LOCATION_ID,A.TYPE AS P_TYPE,A.AUDIT_STATUS,A.COMPANY_ID,"
+" from jxc_t_outbound_info A"
+" left join jxc_t_outbound_detailed B on A.ID=B.OUTBOUND_ID"
2片段:
+" select C.TIME,C.ID,'销售退货' as XSTYPE,D.NUM AS NUMBER,D.PRICE AS D_PRICE,D.NUM*D.PRICE AS TOTAL,"
+" D.PRODUCTS_ID AS P_WARES_ID,C.USER_ID,C.STORAGE_ID AS D_STORAGE_ID,D.LOCATION_ID,'1' AS P_TYPE,C.AUDIT_STATUS,C.COMPANY_ID"
+" from jxc_t_outbound_revise C"
+"left join jxc_t_outbound_revise_detailed D on C.ID=D.OUTBOUND_REVISE_ID"
+") A"
如果片段1和片段2都没有问题,然后将1片段和2片段用Union连上继续测试,以此类推,就可以快速定位问题了。

havedream_one
havedream_one   2016.05.11 20:47

语法错误 ,仔细看看sql语句,可能是不小心写错了,

GHSYue
GHSYue   2016.05.12 11:41

sql语句书写问题应该有第三方的可以使用,

Csdn user default icon
上传中...
上传图片
插入图片