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