【问题标题】:What would be the SQLite query for filtering from local database?从本地数据库过滤的 SQLite 查询是什么?
【发布时间】:2018-08-04 05:39:23
【问题描述】:
在我的本地数据库中,一列保留了全部 json 数据,我想使用查询,我的过滤参数是 json 的键之一。
我看到了一些我们可以使用“json_extract”的帖子,但我不确定它为什么不起作用....
我的查询是这样的
SELECT * FROM table
WHERE ( Type='States' )
AND json_extract(Data, '$.CountryId=1053')
为了您更好地理解,我提供了屏幕截图:
【问题讨论】:
标签:
ios
json
sqlite
extract
【解决方案1】:
json_extract 函数只会为您提取数据。您需要在提取字段后进行比较。试试这个:
SELECT * FROM table WHERE ( Type='States' ) AND json_extract(Data, '$.CountryId') = 1053
或者,根据CountryId 的类型,这可能会更好:
SELECT * FROM table WHERE ( Type='States' ) AND json_extract(Data, '$.CountryId') = '1053'