Android SQLite-在SQLite 3.25.0之前版本中实现等效的行数和窗口结果
Android附带的SQLite版本最多为3.19- 然而,最近,我倾向于执行行数和窗口函数。但是,仅从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中没有此类功能。我想知道,有没有办法不使用行号和窗口就达到同样的效果?它不优雅,但却能工作:
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
)
);