1
我正在使用Cosmos DB,我想编写一个SQL查询以匹配数组中的多个值。为了详细说明,假设您有以下集合:与数组中的多个值匹配的CosmosDB SQL查询
[
{
"id": "31d4c08b-ee59-4ede-b801-3cacaea38808",
"name": "Oliver Queen",
"occupations": [
{
"job_title": "Billionaire",
"job_satisfaction": "pretty good"
},
{
"job_title": "Green Arrow",
"job_satisfaction": "meh"
}
]
},
{
"id": "689bdc38-9849-4a11-b856-53f8628b76c9",
"name": "Bruce Wayne",
"occupations": [
{
"job_title": "Billionaire",
"job_satisfaction": "pretty good"
},
{
"job_title": "Batman",
"job_satisfaction": "I'm Batman"
}
]
},
{
"id": "d1d3609a-0067-47e4-b7ff-afc7ee1a0147",
"name": "Clarke Kent",
"occupations": [
{
"job_title": "Reporter",
"job_satisfaction": "average"
},
{
"job_title": "Superman",
"job_satisfaction": "not as good as Batman"
}
]
}
]
我想编写一个查询将返回与“亿万富翁”和“蝙蝠侠”的JOB_TITLE职业的所有条目。只是要清楚结果必须有两个job_titles。所以在上面的集合中,它只应该返回布鲁斯·韦恩。
到目前为止,我曾尝试:
SELECT c.id, c.name, c.occupations FROM c
WHERE ARRAY_CONTAINS(c.occupations, {'job_title': 'Billionaire' })
AND ARRAY_CONTAINS(c.occupations, {'job_title': 'Batman' })
和
SELECT c.id, c.name, c.occupations FROM c
WHERE c.occupations.job_title = 'Batman'
AND c.occupations.job_title = 'Billionaire'
这两者返回空的结果。
在此先感谢
那完美。谢谢。 –