我有一个可以在工作台上正常运行的mysql查询。
但是当我尝试在使用npm模块mysql的nodejs中执行它时,它给出了错误。
我尝试使用反引号,但没有帮助。
sqlMessage:“您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在'SET @PivotQuery = CONCAT('SELECT Country,',@PivotQuery附近使用,第1行的'FROM TestEmployee GRO'”
SELECT GROUP_CONCAT(CONCAT(' MAX(IF(State= ''',t.State,''', Salary, NULL)) AS ',t.State)) INTO @PivotQuery FROM (SELECT State FROM TestEmployee GROUP BY State) t; SET @PivotQuery = CONCAT('SELECT Country,', @PivotQuery, ' FROM TestEmployee GROUP BY Country'); PREPARE statement FROM @PivotQuery; EXECUTE statement; DEALLOCATE PREPARE statement;