我必须将SQLite数据库“移植”到MySQL。该数据库是使用带有Connector / NET库的C#应用程序设置的。
移植用于创建数据库表的方法很简单,但我陷入了困境。
该视图的SQLite代码工作正常,如下所示:
CREATE VIEW IF NOT EXISTS EXO_ResultsSummaries AS
SELECT ParticipantBIB,
t.HeatIndex,
(CASE WHEN t.QualiGroup IS NULL THEN t.Finals ELSE t.QualiGroup END) AS HeatLevel,
PointsObstacle0 + PointsObstacle1 AS TotalScore, TimeObstacle0 + TimeObstacle1 AS TotalTime
FROM (EXO_Results INNER JOIN Heats ON EXO_Results.HeatIndex = Heats.HeatIndex) t
WHERE t.Completed = 1;
由于“ IF NOT EXISTS”语句不适用于MySQL,因此我将代码更改为以下内容:
CREATE OR REPLACE VIEW EXO_ResultsSummaries AS
SELECT ParticipantBIB,
t.HeatIndex,
(CASE WHEN t.QualiGroup IS NULL THEN t.Finals ELSE t.QualiGroup END) AS HeatLevel,
PointsObstacle0 + PointsObstacle1 AS TotalScore, TimeObstacle0 + TimeObstacle1 AS TotalTime
FROM (EXO_Results INNER JOIN Heats ON EXO_Results.HeatIndex = Heats.HeatIndex) AS t
WHERE t.Completed = 1;
但是,如果尝试从应用程序(或工作台)创建视图,则会出现此错误:
Error Code: 1064. 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 'AS t WHERE t.Completed = 1' at line 6
答案 0 :(得分:0)
感谢Shadow的评论。相应地更改了我的代码,这很好用:
CREATE OR REPLACE VIEW EXO_ResultsSummaries AS SELECT ParticipantBIB,
Heats.HeatIndex,
(CASE WHEN Heats.QualiGroup IS NULL THEN Heats.Finals ELSE Heats.QualiGroup END) AS HeatLevel,
PointsObstacle0 + PointsObstacle1 AS TotalScore, TimeObstacle0 + TimeObstacle1 AS TotalTime
FROM EXO_Results INNER JOIN Heats ON EXO_Results.HeatIndex = Heats.HeatIndex
WHERE Heats.Completed = 1;