- 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 - 联接
- DocumentDB SQL - 别名
- DocumentDB SQL - 数组创建
- DocumentDB - 标量表达式
- DocumentDB SQL - 参数化
- DocumentDB SQL - 内置函数
- Linq 到 SQL 转换
- JavaScript 集成
- 用户定义函数
- 复合 SQL 查询
- DocumentDB SQL 有用的资源
- DocumentDB SQL - 快速指南
- DocumentDB SQL - 有用的资源
- DocumentDB SQL - 讨论
DocumentDB SQL - Where 子句
在本章中,我们将介绍 WHERE 子句,它也是可选的,就像 FROM 子句一样。它用于指定一个条件,以 JSON 文档的形式获取源提供的数据。任何 JSON 文档都必须评估指定条件为“true”才能被视为结果。如果给定的条件得到满足,它才会以 JSON 文档的形式返回特定数据。我们可以使用 WHERE 子句来筛选记录并仅获取必要的记录。
在这个示例中,我们将考虑相同的三个文档。以下是 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
}
我们来看一个使用 WHERE 子句的简单示例。
在此查询中,在 WHERE 子句中指定了 (WHERE f.id = "WakefieldFamily") 条件。
SELECT * FROM f WHERE f.id = "WakefieldFamily"
当执行上述查询时,它将返回 WakefieldFamily 的完整 JSON 文档,如下面的输出所示。
[
{
"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,
"_rid": "Ic8LAJFujgECAAAAAAAAAA==",
"_ts": 1450541623,
"_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgECAAAAAAAAAA==/",
"_etag": "\"00000500-0000-0000-0000-567582370000\"",
"_attachments": "attachments/"
}
]
广告