[英]How can I write a compound WHERE condition using documentdb?
I have a document that looks like this: 我有一个看起来像这样的文档:
{
"email": "joan.smith@somedomain.com",
"name": {
"first": "Joan",
"last": "Smith"
}
}
How can I write a SQL query that uses a compound comparison against the entire last name? 如何编写对整个姓氏使用复合比较的SQL查询?
This is effectively what I'd like to do in the WHERE: 实际上,这是我想在WHERE中执行的操作:
SELECT *
FROM c
WHERE c.name.first + " " + c.name.last = "Joan Smith"
The "plural" version “复数”版本
SELECT *
FROM c
WHERE c.name.first + " " + c.name.last
IN ("Joan Smith", "Juan Suarez")
Both of these queries will run in the Azure Portal without error, but they return empty results. 这两个查询都将在Azure门户中正确运行,但是它们返回空结果。 I have tried wrapping the concatenation in parentheses but this has no effect.
我尝试将连接用括号括起来,但这没有效果。
According to the Cosmos DB SQL APIs , if you want to implement concatenation in Cosmos DB SQL, you need to use || 根据Cosmos DB SQL API ,如果要在Cosmos DB SQL中实现串联,则需要使用||。 instead of + .
代替+ 。
So, please modify your sql as below: 因此,请按如下所示修改您的sql:
SELECT c.id,c.name
FROM c
WHERE c.name.first || " " || c.name.last = "Joan Smith"
Then you could get the results you want. 然后,您可以获得所需的结果。
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.