- DocumentDB SQL 教程
- DocumentDB SQL - 主页
- DocumentDB SQL - 概述
- DocumentDB SQL - 选择子句
- DocumentDB SQL - 从子句
- DocumentDB SQL - Where 子句
- DocumentDB SQL - 运算符
- DocumentDB - 关键字 Between
- DocumentDB SQL - 关键字 In
- DocumentDB SQL - 关键字 Value
- DocumentDB SQL - Order By 子句
- DocumentDB SQL - 迭代
- DocumentDB SQL - 联接
- DocumentDB SQL - 别名
- DocumentDB SQL - 数组创建
- DocumentDB - 标量表达式
- DocumentDB SQL - 参数化
- DocumentDB SQL - 内置函数
- Linq to SQL 翻译
- JavaScript 集成
- 用户定义函数
- 复合 SQL 查询
- DocumentDB SQL 有用资源
- DocumentDB SQL - 快速指南
- DocumentDB SQL - 有用资源
- DocumentDB SQL - 讨论
DocumentDB SQL——关键字 Between
关键字 BETWEEN 用于表示对值范围的查询,就像在 SQL 中一样。BETWEEN 可用于字符串或数字。在 DocumentDB 与 ANSI SQL 中使用 BETWEEN 的主要区别在于,您可针对混合类型的属性表示范围查询。
例如,在某些文档中,可能将“grade”设为数字,而其他文档中,可能将其设为字符串。在这些情况下,“未定义”两个不同类型的结果之间的比较,并且文档将被跳过。
让我们考虑前一个示例中的三个文档。以下是 **AndersenFamily** 文档。
{ "id": "AndersenFamily", "lastName": "Andersen", "parents": [ { "firstName": "Thomas", "relationship": "father" }, { "firstName": "Mary Kay", "relationship": "mother" } ], "children": [ { "firstName": "Henriette Thaulow", "gender": "female", "grade": 5, "pets": [ { "givenName": "Fluffy", "type": "Rabbit" } ] } ], "location": { "state": "WA", "county": "King", "city": "Seattle" }, "isRegistered": true }
以下是 **SmithFamily** 文档。
{ "id": "SmithFamily", "parents": [ { "familyName": "Smith", "givenName": "James" }, { "familyName": "Curtis", "givenName": "Helen" } ], "children": [ { "givenName": "Michelle", "gender": "female", "grade": 1 }, { "givenName": "John", "gender": "male", "grade": 7, "pets": [ { "givenName": "Tweetie", "type": "Bird" } ] } ], "location": { "state": "NY", "county": "Queens", "city": "Forest Hills" }, "isRegistered": true }
以下是 **WakefieldFamily** 文档。
{ "id": "WakefieldFamily", "parents": [ { "familyName": "Wakefield", "givenName": "Robin" }, { "familyName": "Miller", "givenName": "Ben" } ], "children": [ { "familyName": "Merriam", "givenName": "Jesse", "gender": "female", "grade": 6, "pets": [ { "givenName": "Charlie Brown", "type": "Dog" }, { "givenName": "Tiger", "type": "Cat" }, { "givenName": "Princess", "type": "Cat" } ] }, { "familyName": "Miller", "givenName": "Lisa", "gender": "female", "grade": 3, "pets": [ { "givenName": "Jake", "type": "Snake" } ] } ], "location": { "state": "NY", "county": "Manhattan", "city": "NY" }, "isRegistered": false }
让我们看一个示例,其中查询返回所有第一个孩子成绩在 1-5 之间(包括 1 和 5)的家庭文档。
以下是使用关键字 BETWEEN 然后使用逻辑运算符 AND 的查询。
SELECT * FROM Families.children[0] c WHERE c.grade BETWEEN 1 AND 5
执行上述查询时,会生成以下输出。
[ { "givenName": "Michelle", "gender": "female", "grade": 1 }, { "firstName": "Henriette Thaulow", "gender": "female", "grade": 5, "pets": [ { "givenName": "Fluffy", "type": "Rabbit" } ] } ]
要显示超出前一个示例范围的成绩,请如以下查询中所示使用 NOT BETWEEN。
SELECT * FROM Families.children[0] c WHERE c.grade NOT BETWEEN 1 AND 5
执行此查询时,会产生以下输出。
[ { "familyName": "Merriam", "givenName": "Jesse", "gender": "female", "grade": 6, "pets": [ { "givenName": "Charlie Brown", "type": "Dog" }, { "givenName": "Tiger", "type": "Cat" }, { "givenName": "Princess", "type": "Cat" } ] } ]
广告