n1ql multiple unnest in select statement with multiple where condition
n1ql multiple unnest in select statement with multiple where condition
以下是 couchbase 中的示例文档之一。
{
"name":"abc",
"friends":["a","b","c"],
"bestfriends":["x","y","z"]
}
我想根据 "friends" 和 "bestfriends" 上的特定条件显示 "name"。
n1ql 查询
select s.name from userdetails s
unnest s.friends as f
unnest s.bestfriends as bf
where f="a" or bf="a"
如果两个数组(friends、bestfriends)都不是空数组,以上查询工作正常。
但是,即使数组中的任何一个为空数组(即"bestfriends":[]),结果也为空。如何克服这个问题?
在这两种情况下都使用 LEFT OUTER UNNEST。
以下是 couchbase 中的示例文档之一。
{
"name":"abc",
"friends":["a","b","c"],
"bestfriends":["x","y","z"]
}
我想根据 "friends" 和 "bestfriends" 上的特定条件显示 "name"。
n1ql 查询
select s.name from userdetails s
unnest s.friends as f
unnest s.bestfriends as bf
where f="a" or bf="a"
如果两个数组(friends、bestfriends)都不是空数组,以上查询工作正常。
但是,即使数组中的任何一个为空数组(即"bestfriends":[]),结果也为空。如何克服这个问题?
在这两种情况下都使用 LEFT OUTER UNNEST。