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查询以获取包含在firstname或lastname中的搜索文本的下一个可用字符_Android_Sqlite_Android Sqlite - Fatal编程技术网

Android Sqlite查询以获取包含在firstname或lastname中的搜索文本的下一个可用字符

Android Sqlite查询以获取包含在firstname或lastname中的搜索文本的下一个可用字符,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,如何查询sqlite数据库,以在两列中搜索关键字后获得下一个可用字符的列表。例如,如果搜索关键字为“and” 并将列设为firstname和lastname: And[y] Xyz And[r]ew And[z] Xyz And[o]n Mirand[a] Lorand[e] 然后我应该得到字符[y,r,z,o,a,e] 我尝试使用substr和instr,但我无法编写一个同时查找名字和姓氏并返回下一个字符的查询。使用UNION ALL对两列中的值进行查询,并使用rowid获得正确的顺序: s

如何查询sqlite数据库,以在两列中搜索关键字后获得下一个可用字符的列表。例如,如果搜索关键字为“and” 并将列设为firstname和lastname:

And[y] Xyz
And[r]ew And[z]
Xyz And[o]n
Mirand[a] Lorand[e]
然后我应该得到字符[y,r,z,o,a,e]


我尝试使用substr和instr,但我无法编写一个同时查找名字和姓氏并返回下一个字符的查询。

使用
UNION ALL对两列中的值进行查询,并使用rowid获得正确的顺序:

select nextchar from (
  select
    1 col, 
    rowid,
    substr(firstname, instr(lower(firstname), 'and') + 3, 1) nextchar
  from names 
  where firstname like '%and%'
  union all 
  select
    2, 
    rowid,
    substr(lastname, instr(lower(lastname), 'and') + 3, 1)
  from names 
  where lastname like '%and%'
) t
order by t.rowid, t.col
请参阅。
结果:

如果要将结果作为逗号分隔的字符串,请使用
group\u concat()

请参阅。
结果:


使用
UNION ALL
获取两列中的值,并使用rowid获得正确的顺序:

select nextchar from (
  select
    1 col, 
    rowid,
    substr(firstname, instr(lower(firstname), 'and') + 3, 1) nextchar
  from names 
  where firstname like '%and%'
  union all 
  select
    2, 
    rowid,
    substr(lastname, instr(lower(lastname), 'and') + 3, 1)
  from names 
  where lastname like '%and%'
) t
order by t.rowid, t.col
请参阅。
结果:

如果要将结果作为逗号分隔的字符串,请使用
group\u concat()

请参阅。
结果:


rowid是什么?在SQLite中,每一行都有一个数字id,这是
rowid
。我使用它来保持行的顺序。在这里找到更多信息:什么是rowid?在SQLite中,每一行都有一个数字id,这是
rowid
。我使用它来保持行的顺序。请在此处查找更多信息:
select group_concat(nextchar) chars from (
  select nextchar from (
    select
      1 col, 
      rowid,
      substr(firstname, instr(lower(firstname), 'and') + 3, 1) nextchar
    from names 
    where firstname like '%and%'
    union all 
    select
      2, 
      rowid,
      substr(lastname, instr(lower(lastname), 'and') + 3, 1)
    from names 
    where lastname like '%and%'
  ) t
  order by t.rowid, t.col
)
| chars       |
| ----------- |
| y,r,z,o,a,e |