在MYSQL数据库中存储查询时,在使用换行符/空格时会出错

时间:2013-03-22 17:50:38

标签: mysql

我有一些存储在MYSQL数据库中的查询,然后从数据库中提取并在例程中运行。当我使用没有换行符/标签将它们插入到数据库中时,查询运行正常,但是当我尝试运行相同的查询格式时(我希望以后我需要更新查询)我收到错误。这是一个有效的例子和一个没有的例子(它们与代码相同)

IF(@last_ranking <> formula, @current_rankings := @current_rankings + 1, @current_rankings)  AS rank, @last_ranking := formula, prequery.team, prequery.formula FROM (select @current_rankings := 0) sqlvars, (SELECT team, SUM(formula) AS formula FROM (SELECT g.home_team AS team, SUM(CASE WHEN t.team_id IS NULL THEN 0 ELSE g.home_wins END) AS formula FROM games g LEFT JOIN _top_10 AS t ON g.away_team = t.team_id WHERE g.season = ? AND g.completed = 1 GROUP BY team UNION ALL SELECT g.away_team AS team, SUM(CASE WHEN t2.team_id IS NULL THEN 0 ELSE g.away_wins END) AS formula FROM games g LEFT JOIN _top_10 AS t2 ON g.home_team = t2.team_id WHERE g.season = ? AND g.completed = 1 GROUP BY team) AS Alias,(SELECT @current_rankings := 0, @last_ranking := 0) r GROUP BY team ORDER BY formula DESC ) prequery;

        IF(@last_ranking <> formula, @current_rankings := @current_rankings + 1, @current_rankings)  AS rank, 
         @last_ranking := formula, 
         prequery.team, 
         prequery.formula 
 FROM    (select @current_rankings := 0) sqlvars, 
         (SELECT     team, 
                     SUM(formula) AS formula 
         FROM        (SELECT     g.home_team AS team, 
                                 SUM(CASE WHEN t.team_id IS NULL THEN 0 ELSE g.home_wins END) AS formula 
                     FROM        games g 
                     LEFT JOIN   _top_10 AS t ON g.away_team = t.team_id 
                     WHERE       g.season = ? AND 
                                 g.completed = 1 
                     GROUP BY    team
         UNION ALL   SELECT      g.away_team AS team, 
                                 SUM(CASE WHEN t2.team_id IS NULL THEN 0 ELSE g.away_wins END) AS formula 
                     FROM        games g 
                     LEFT JOIN   _top_10 AS t2 ON g.home_team = t2.team_id 
                     WHERE       g.season = ? AND 
                                 g.completed = 1 
                     GROUP BY    team) AS Alias,
         (SELECT @current_rankings := 0, @last_ranking := 0) r 
 GROUP BY team 
 ORDER BY formula DESC ) prequery;

这笔交易是什么?有没有办法用数据库中的空格存储信息,但在运行查询时动态删除换行符/制表符/不必要的空格?

我得到的错误是

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 '' at line 18

0 个答案:

没有答案