- DocumentDB SQL 教程
- DocumentDB SQL - 主頁
- DocumentDB SQL - 概述
- DocumentDB SQL - Select 子句
- DocumentDB SQL - From 子句
- DocumentDB SQL - Where 子句
- DocumentDB SQL - 運算子
- DocumentDB - Between 關鍵字
- DocumentDB SQL - In 關鍵字
- DocumentDB SQL - 值關鍵字
- 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 - 值關鍵字
當你瞭解到自己只返回一個值時,VALUE 關鍵字就可以透過避免建立成熟物件而幫助生成瘦身結果集。 VALUE 關鍵字提供了一個返回 JSON 值的方法。
讓我們看一個簡單的例子。
下面是具有 VALUE 關鍵字的查詢。
SELECT VALUE "Hello World, this is DocumentDB SQL Tutorial"
當執行此查詢時,它返回標量"Hello World, this is DocumentDB SQL Tutorial"。
[ "Hello World, this is DocumentDB SQL Tutorial" ]
在另一個示例中,讓我們考慮前一個示例中的三個文件。
以下是 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
}
以下是查詢。
SELECT VALUE f.location FROM Families f
當執行此查詢時,它會返回沒有位置標籤的地址。
[
{
"state": "NY",
"county": "Manhattan",
"city": "NY"
},
{
"state": "NY",
"county": "Queens",
"city": "Forest Hills"
},
{
"state": "WA",
"county": "King",
"city": "Seattle"
}
]
如果我們現在不使用 VALUE Keyword 指定相同的查詢,則它將返回帶有位置標籤的地址。以下是查詢。
SELECT f.location FROM Families f
當執行此查詢時,它會生成以下輸出。
[
{
"location": {
"state": "NY",
"county": "Manhattan",
"city": "NY"
}
},
{
"location": {
"state": "NY",
"county": "Queens",
"city": "Forest Hills"
}
},
{
"location": {
"state": "WA",
"county": "King",
"city": "Seattle"
}
}
]
廣告