我想从具有 FieldName=Field4 的元素中选择值 ('Value'),其中值 ('Value') 从具有 FieldName=Field2 的元素中为空。
{
"FormName":"Form1",
"Id": "ID1",
"Module":{
"ModuleType":"Form",
"Layout":"Vertical",
"ControlList":[
{
"ControlType":"Widget",
"Layout":"Vertical",
"FieldList":[
{
"FieldType":"TextBox",
"FieldName":"Field1",
"Value":"field1"
},
{
"FieldType":"TextBox",
"FieldName":"Field2",
"Value":null
},
{
"FieldType":"TextBox",
"FieldName":"Field1",
"Value":"field3"
}
]
},
{
"ControlType":"Widget",
"Layout":"Vertical",
"FieldList":[
{
"row":[
{
"FieldType":"TextBox",
"FieldName":"Field3",
"Value":"field3"
},
{
"FieldType":"TextBox",
"FieldName":"Field4",
"Value":"field4"
}
]
}
]
}
]
}
}
我了解如何获得正确的数据集:select
form.Id
from
`test` as form
where
any cl in form.Module.ControlList satisfies
any fl in cl.FieldList satisfies fl.FieldName = 'Field2' AND fl.`Value` is null
end
end;
...返回:[
{
"Id": "ID1"
}
]
但是我的 select 语句应该如何得到这个:[
{
"Value": "field4"
}
]
最佳答案
SELECT
ARRAY_FLATTEN((ARRAY (ARRAY (ARRAY {r.`Value`}
FOR r IN f.`row`
WHEN r.FieldName = "Field4"
END)
FOR f IN c.FieldList
END)
FOR c IN t.Module.ControlList
END),3)[0].*
FROM `test` AS t
WHERE (ANY cl IN t.Module.ControlList
SATISFIES (ANY fl IN cl.FieldList
SATISFIES fl.FieldName = 'Field2' AND fl.`Value` IS NULL
END)
END);
关于couchbase - 如何从兄弟数组中选择字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64433414/