Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLite-在SQLite 3.25.0之前版本中实现等效的行数和窗口结果_Android_Sqlite - Fatal编程技术网

Android SQLite-在SQLite 3.25.0之前版本中实现等效的行数和窗口结果

Android SQLite-在SQLite 3.25.0之前版本中实现等效的行数和窗口结果,android,sqlite,Android,Sqlite,Android附带的SQLite版本最多为3.19- 然而,最近,我倾向于执行行数和窗口函数。但是,仅从3.25.0开始支持- 我的目的是使用行号和窗口功能实现以下功能- 但是,Android中没有此类功能。我想知道,有没有办法不使用行号和窗口就达到同样的效果?它不优雅,但却能工作: update plain_note set "order" = ( select count(*) from plain_note p where p.title > plain_note.

Android附带的SQLite版本最多为3.19-

然而,最近,我倾向于执行行数和窗口函数。但是,仅从3.25.0开始支持-

我的目的是使用行号和窗口功能实现以下功能-


但是,Android中没有此类功能。我想知道,有没有办法不使用行号和窗口就达到同样的效果?

它不优雅,但却能工作:

update plain_note 
set "order" = (
  select count(*) 
  from plain_note p 
  where p.title > plain_note.title 
  or ( 
    p.title = plain_note.title 
    and 
    case when p.type = 0 then p.body else p.searched_string end > 
    case when plain_note.type = 0 then plain_note.body else plain_note.searched_string end
  ) 
  or (
    p.title = plain_note.title 
    and 
    coalesce(case when p.type = 0 then p.body else p.searched_string end, '') = 
    coalesce(case when plain_note.type = 0 then plain_note.body else plain_note.searched_string end, '')
    and 
    p.rowid < plain_note.rowid 
  )
);

这不是由多次计数*评估造成的性能损失吗?当然是性能损失。您无法将其与窗口函数进行比较。唯一的替代方法是使用rowid,但不能依赖其值。
update plain_note 
set "order" = (
  select count(*) 
  from plain_note p 
  where p.title > plain_note.title 
  or ( 
    p.title = plain_note.title 
    and 
    case when p.type = 0 then p.body else p.searched_string end > 
    case when plain_note.type = 0 then plain_note.body else plain_note.searched_string end
  ) 
  or (
    p.title = plain_note.title 
    and 
    coalesce(case when p.type = 0 then p.body else p.searched_string end, '') = 
    coalesce(case when plain_note.type = 0 then plain_note.body else plain_note.searched_string end, '')
    and 
    p.rowid < plain_note.rowid 
  )
);