0

我有一些查询存储在 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
4

0 回答 0