SQLite在子查询中导致语法问题

SQLite在子查询中导致语法问题,sqlite,flutter,sqflite,Sqlite,Flutter,Sqflite,以下是我在SQLite的DB Browser上运行它的代码: SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY recipe_name) AS rn, rt.* FROM SyncRecipeIngredientTable sr JOIN RecipeIngredientTable ri ON ri.recipe_ingredient_id = sr.recipe_ingredient_id

以下是我在SQLite的DB Browser上运行它的代码:

SELECT *
  FROM
  (SELECT ROW_NUMBER() OVER (PARTITION BY recipe_name) AS rn, rt.*
     FROM SyncRecipeIngredientTable sr
     JOIN RecipeIngredientTable ri
       ON ri.recipe_ingredient_id = sr.recipe_ingredient_id
     JOIN RecipeTable rt
       ON rt.recipe_id = sr.recipe_id
    WHERE ri.recipe_item_name in  ("ayva", "su", "pirinç")
      GROUP by
      rt.recipe_id HAVING COUNT(*) >= 3)
 WHERE rn = 1
它在那里工作得很好,就像预期的那样。但当我将这个代码块移动到Flatter的sqflite时,如下所示:

List<Map<String, dynamic>> foundRecipeList = await db.rawQuery("""
    SELECT *
      FROM
      (SELECT ROW_NUMBER() OVER (PARTITION BY recipe_name) AS rn, rt.*
         FROM SyncRecipeIngredientTable sr
         JOIN RecipeIngredientTable ri
           ON ri.recipe_ingredient_id = sr.recipe_ingredient_id
         JOIN RecipeTable rt
           ON rt.recipe_id = sr.recipe_id
        WHERE ri.recipe_item_name in ($finalStr)
          GROUP by
          rt.recipe_id HAVING COUNT(*) >= 3)
     WHERE rn = 1
""");
这给我带来了一个问题:

I/flutter ( 7208): AsyncSnapshot<dynamic>(ConnectionState.waiting, null, DatabaseException(near "(": syntax error (code 1): , while compiling: SELECT *
I/flutter ( 7208):   FROM
I/flutter ( 7208):   (SELECT ROW_NUMBER() OVER (PARTITION BY recipe_name) AS rn, rt.*
I/flutter ( 7208):      FROM SyncRecipeIngredientTable sr
I/flutter ( 7208):      JOIN RecipeIngredientTable ri
I/flutter ( 7208):        ON ri.recipe_ingredient_id = sr.recipe_ingredient_id
I/flutter ( 7208):      JOIN RecipeTable rt
I/flutter ( 7208):        ON rt.recipe_id = sr.recipe_id
I/flutter ( 7208):     WHERE ri.recipe_item_name in ('su','pirinç','ayva')
I/flutter ( 7208):    GROUP by
I/flutter ( 7208):     rt.recipe_id HAVING COUNT(*) >= 3)
I/flutter ( 7208):  WHERE rn = 1
I/flutter ( 7208): #################################################################
I/flutter ( 7208): Error Code : 1 (SQLITE_ERROR)
I/flutter ( 7208): Caused By : SQL(query) error or missing database.
I/flutter ( 7208):  (near "(": syntax error (code 1): , while compiling: SELECT *
I/flutter ( 7208):   FROM
I/flutter ( 7208):   (SELECT ROW_NUMBER() OVER (PARTITION BY recipe_name) AS rn, rt.*
I/flutter ( 7208):      FROM SyncRecipeIngredientTable sr
I/flutter ( 7208):      JOIN RecipeIngredientTable ri
I/flutter ( 7208):        ON ri.recipe_ingredient_id = sr.recipe_ingredient_id
I/flutter ( 7208):      JOIN RecipeTable rt
I/flutter ( 7208):        ON rt.recipe_id = sr.recipe_id
I/flutter ( 7208):     WHERE ri.reci

如何解决此问题?

您的程序使用的sqlite版本太旧,不支持窗口功能。