我正在使用MySQL控制中心来测试一些在我的代码中引发错误的SQL语句。每次我测试它都没有给出错误是什么的错误,错误在哪里。它只是列出了整个声明,并说它在那里的某个地方。这是Borland的声明,它给了我一个错误:
sprintf(sql, "CREATE TABLE %s AS "
"SELECT "
" LPAD(V0_X1_A3, 13, ' ') AS V0_X1_A3, "
" SUM (F5*F6) AS CostExt, "
" IFNULL(V0_X1_A2, 0.00000) AS V0_X1_A2, "
" SUM(F6) AS F6 "
"FROM _TransRecords "
" LEFT OUTER JOIN _V0_X1 ON V0_X1_PK = V0_X1_FK "
"WHERE %s "
" GROUP BY V0_X1_A3 ", TblName, where);
我将语法编辑为:
sprintf(sql, "CREATE TABLE %s AS "
" SELECT "
" SUM (F5*F6) AS CostExt, "
" SUM(F6) AS F6 "
" FROM _TransRecords "
" LPAD(V0_X1_A3, 13, ' ') AS V0_X1_A3, "
" IFNULL(V0_X1_A2, 0.00000) AS V0_X1_A2, "
" FROM _V0_X1 "
" LEFT OUTER JOIN _V0_X1 ON V0_X1_PK = V0_X1_FK "
" WHERE %s "
" GROUP BY V0_X1_A3 ", TblName, where);
答案 0 :(得分:0)
JOIN
语法存在问题,因为您未在ON
条件中指定表名。
我猜测一个解决方案(因为我不知道哪些列属于哪个表):
"CREATE TABLE %s AS "
"SELECT "
" LPAD(V0_X1_A3, 13, ' ') AS V0_X1_A3, "
" SUM (F5*F6) AS CostExt, "
" IFNULL(V0_X1_A2, 0.00000) AS V0_X1_A2, "
" SUM(F6) AS F6 "
"FROM _TransRecords "
" LEFT OUTER JOIN _V0_X1 ON _TransRecords.V0_X1_PK = _V0_X1.V0_X1_FK "
"WHERE %s "
" GROUP BY V0_X1_A3 "
答案 1 :(得分:0)
我得到了它的工作。这是我的代码。
sprintf(sql, "CREATE TABLE %s AS "
" SELECT "
" SUM(F5*F6) AS CostExt, "
" SUM(F6) AS F6, "
" LPAD(V0_X1_A3, 13, ' ') AS V0_X1_A3, "
" IFNULL(V0_X1_A2, 0.00000) AS V0_X1_A2, "
" SUM(V0_X1_A2*F6) AS RetailExt "
" FROM _TransRecords "
" LEFT OUTER JOIN _V0_X1 ON V0_X1_PK = V0_X1_FK "
" WHERE %s "
" GROUP BY V0_X1_A3 ", TblName, where);