简体   繁体   English

如何使用documentdb编写复合WHERE条件?

[英]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.

相关问题 如何在 firebase 中编写复合查询? - How do I write a compound query in firebase? 如何在 setConfirmDialog() 中写入条件 - How can I write condition in setConfirmDialog() 我如何在 javascript(Reactjs) 中编写此条件 - how I can write this condition in javascript(Reactjs) 如何根据 if 条件在 firebase 查询中添加 where 条件? - How can i add where condition in firebase query based on if condition? 如何在DocumentDB中使用使用多个集合的存储过程 - How can I use stored procedures in DocumentDB that use multiple collections 如何编写自定义 where 条件原始查询? - How to write custom where condition raw query? 不使用document.write,如何在执行当前JS的地方插入DOM节点? - Without using document.write how can I insert a DOM node where the current JS is executing? 如何编写一个 function,我可以在其中将枚举的键作为字符串传递并获取映射到它的值? 使用 angular 11 - How to write a function where I can pass the key of the enum as a string and get the value mapped to it? Using angular 11 如何在documentdb中编写查询以匹配精确数组? - How to write query in documentdb to match exact arrays? 在Azure DocumentDB中编写SP时在哪里可以获得JS对象/功能的参考 - Where can I get a reference for the JS objects/Functions when writing SP in Azure DocumentDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM