- 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/"
}
]
廣告