select 来自 SQLite 中 json 列的不同键

select distinct keys from a json column in SQLite

SQLite 数据库的 TEXT 列包含 json 个值,如下所示:

[{"key1":"116"},{"key2":"260"},{"key3":"123"},{"key4":"1155"},{"key4":"1507"}]

我需要一个不同的 json 键列表

key1 1
key2 1
key3 1
key4 2

我可以仅使用 sqlite json 函数编写 VIEW 吗?

您需要 JSON1 Extension 函数,例如 json_each() 和聚合:

SELECT j.key, COUNT(*) counter
FROM (
  SELECT j.*
  FROM tablename t, json_each(col) j
  -- WHERE ...  (if you want to apply a filter in the table's rows)
) t, json_each(t.value) j  
GROUP BY j.key;

demo