如何仅从数组中获取特定字段
How to get particular fields only from array
我有
[
{
"some-app": {
"name": test,
"age": "34",
"company": [
{
"year": "2021",
"pa_flag": "N",
...
},
{
"year": "2022",
"pa_flag": "Y",
.....
},
.....
],
}
}
]
我只想select姓名、年龄company.year和company.pa_flag
我在努力
Select name, age company.year and company.pa_flag FROM some-app LIMIT 10
但它只显示姓名和年龄列
使用[*]
数组语法。例如:
select a.company[*].year
from soquestions._default.`some-app` a
(我使用 Couchbase 7 将你的文档放在一个名为 some-app 的集合中,但如果你使用的是旧版本并且只是在存储桶级别查询,同样的事情应该有效。
还有那个 returns:
[
{
"year": [
"2021",
"2022"
]
}
]
您可以 re-construct 使用子查询表达式以您想要的方式排列。
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/subqueries.html#subquery-n1ql-exp
SELECT a.name,
a.age,
(SELECT c.year, c.pa_flag
FORM a.company AS c
WHERE c.year > "2000"
ORDER BY c.year
OFFSET 0
LIMIT 10
) AS company
FROM `some-app` AS a
LIMIT 10;
我有
[
{
"some-app": {
"name": test,
"age": "34",
"company": [
{
"year": "2021",
"pa_flag": "N",
...
},
{
"year": "2022",
"pa_flag": "Y",
.....
},
.....
],
}
}
]
我只想select姓名、年龄company.year和company.pa_flag
我在努力
Select name, age company.year and company.pa_flag FROM some-app LIMIT 10
但它只显示姓名和年龄列
使用[*]
数组语法。例如:
select a.company[*].year
from soquestions._default.`some-app` a
(我使用 Couchbase 7 将你的文档放在一个名为 some-app 的集合中,但如果你使用的是旧版本并且只是在存储桶级别查询,同样的事情应该有效。
还有那个 returns:
[
{
"year": [
"2021",
"2022"
]
}
]
您可以 re-construct 使用子查询表达式以您想要的方式排列。 https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/subqueries.html#subquery-n1ql-exp
SELECT a.name,
a.age,
(SELECT c.year, c.pa_flag
FORM a.company AS c
WHERE c.year > "2000"
ORDER BY c.year
OFFSET 0
LIMIT 10
) AS company
FROM `some-app` AS a
LIMIT 10;