作为更大的选择查询的一部分,我需要从 json 数组的对象中提取值作为逗号分隔的字符串。
我已经设法从 json 对象中获取 json 数组:
SELECT * FROM (SELECT json_extract(Site.Login, '$.Uris') FROM Site);
给出相同结果的第二个变体:
SELECT value FROM json_each(Site.Login), Site WHERE json_each.key = 'Uris';
单行的测试给出了想要的结果:
SELECT group_concat(json_extract(value, '$.Uri')) as login_uri FROM json_each('[{"Uri":"https://cnn.com"},{"Uri":"https://bbc.com"},{"Uri":"https://reuters.com"}]');
我迷失在矩阵中。我尝试了各种方法来组合上面的查询代码,但我无法取得任何进展。
Site.Login 单元格的示例。Uri 对象的数量可以从 0 到无穷大。
{
"Uris": [
{"Uri":"https://cnn.com"},
{"Uri":"https://bbc.com"},
{"Uri":"https://reuters.com"}
],
"Username": "ghhhhhhhhhhhhhfgggggggggggggggg",
"Password": "hgfhfghfghfgh",
"PasswordRevisionDate": "2019-01-07T21:51:42.65Z",
"Totp": "gffffffffffffffffffffffhhhhhhhhhhhhhhhfghghgfh",
"Name": "hgfhfghfghfghfgh",
"PasswordHistory": [
{
"Password": "ghfghfghfghfghfg",
"LastUsedDate": "2019-01-07T21:51:42.65Z"
}
]
}
Site 表的完整布局:
CREATE TABLE "Site" (
"Id" varchar primary key not null ,
"FolderId" varchar ,
"UserId" varchar ,
"OrganizationId" varchar ,
"Name" varchar ,
"Notes" varchar ,
"Fields" varchar ,
"PasswordHistory" varchar ,
"Login" varchar ,
"Card" varchar ,
"Identity" varchar ,
"SecureNote" varchar ,
"Favorite" integer ,
"Edit" integer ,
"OrganizationUseTotp" integer ,
"RevisionDateTime" bigint ,
"Type" integer ,
"Data" varchar )
选择查询应返回一个名为 login_uri 的列,其中包含作为连接字符串提取的 json 数组对象值: https://cnn.com、https://bbc.com、https://reuters.com