如果其他数据不存在,我们有想要返回的数据。考虑可以返回的默认值,但是如果指定了特定值,我们则需要这些默认值。但是对于JOIN来说,如果特定值不存在,则不会返回该文档。没有LEFT加入。没有示例很难解释,因此请检查代码。
尝试了各种join和where语句,无法找到有效的语句。
SELECT
c.myId,
(IS_DEFINED(dm.code) ? tm.code : dm.code) as code
FROM c
JOIN dm in c.modelData
JOIN tm in c.modelData
WHERE c.partitionKey="8"
AND dm.dataScope = "default"
and tm.dataScope = "other"
示例数据为
[
{
"myId": "1",
"partitionKey": "8",
"values": [
{
"dataScope": "default",
"code": "1"
},
{
"dataScope": "other",
"code": "1a"
}
],
"id": "ba884879-9b9b-3ff2-dc08-ca6168892ca5"
},
{
"myId": "2",
"partitionKey": "8",
"values": [
{
"dataScope": "default",
"code": "1a"
},
{
"dataScope": "other",
"code": "2"
}
],
"id": "864625c2-50de-5d56-9626-26b04d8ff1f2"
},
{
"myId": "3",
"partitionKey": "8",
"values": [
{
"dataScope": "default",
"code": "1a"
},
{
"dataScope": "other",
"valuesProperty": "true"
}
],
"id": "b414d2da-56c7-dff9-0cf5-5350f215639e"
},
{
"myId": "4",
"partitionKey": "8",
"values": [
{
"dataScope": "default",
"code": "2"
}
],
"id": "9df94567-5069-452c-4c1e-99ee2e72480c"
}
]
我们想要得到的是这样的:
[
{
"myId": "1",
"code": "1a"
},
{
"myId": "2",
"code": "2"
},
{
"myId": "3",
"code": "1a"
},
{
"myId": "4",
"code": "2"
}
]
我们得到的通常是这样的:
[
{
"myId": "1",
"code": "1a"
},
{
"myId": "2",
"code": "2"
},
{
"myId": "3"
}
]
标题已编辑,也许会有更多的人阅读,并希望能得到答复。