- DocumentDB SQL 教程
- DocumentDB SQL - 主页
- DocumentDB SQL - 概览
- DocumentDB SQL - SELECT 子句
- DocumentDB SQL - FROM 子句
- 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 到 SQL 转换
- JavaScript 集成
- 用户定义函数
- 复合 SQL 查询
- DocumentDB SQL 有用资源
- DocumentDB SQL - 快速指南
- DocumentDB SQL - 有用资源
- DocumentDB SQL - 讨论
DocumentDB SQL - IN 关键字
IN 关键字可用于检查指定值是否与列表中的任何值匹配。IN 运算符允许你在 WHERE 子句中指定多个值。IN 等效于链接多个 OR 子句。
将之前示例中处理过的三个文档视为相似。以下是 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 }
我们来看一个简单的示例。
以下是将检索其 familyName 为“Smith”或 Wakefield 的数据的查询。
SELECT * FROM Families.parents[0] f WHERE f.familyName IN ('Smith', 'Wakefield')
当执行上述查询时,它会产生以下输出。
[ { "familyName": "Wakefield", "givenName": "Robin" }, { "familyName": "Smith", "givenName": "James" } ]
让我们考虑另一个简单示例,其中所有家庭文档都将被检索,其中 id 为“SmithFamily”或“AndersenFamily”。以下是查询。
SELECT * FROM Families WHERE Families.id IN ('SmithFamily', 'AndersenFamily')
当执行上述查询时,它会产生以下输出。
[ { "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, "_rid": "Ic8LAJFujgEDAAAAAAAAAA==", "_ts": 1450541623, "_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgEDAAAAAAAAAA==/", "_etag": "\"00000600-0000-0000-0000-567582370000\"", "_attachments": "attachments/" }, { "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, "_rid": "Ic8LAJFujgEEAAAAAAAAAA==", "_ts": 1450541624, "_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgEEAAAAAAAAAA==/", "_etag": "\"00000700-0000-0000-0000-567582380000\"", "_attachments": "attachments/" } ]
广告