开发手册 欢迎您!
软件开发者资料库

DocumentDB SQL - 值关键字

DocumentDB SQL值关键字 - 从概述,选择子句,从子句,子句,操作符,关键字,关键字,值关键字,按顺序子句,迭代,连接,别名,数组创建,简单而简单的步骤学习DocumentDB SQL标量表达式,参数化SQL,内置函数,Linq到SQL转换,JavaScript集成,用户定义函数,复合SQL查询。

当您知道只返回单个值时,VALUE关键字可以通过避免创建完整对象的开销来帮助生成更精简的结果集. VALUE关键字提供了一种返回JSON值的方法.

让我们看一个简单的例子.

Value Key<a href=Word"/>

以下是带有VALUE关键字的查询.

SELECT VALUE "Hello World, this is DocumentDB SQL Tutorial"

执行此查询时,它返回标量"Hello World,这是DocumentDB SQL教程" .

[    "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关键字,那么它将返回带有位置标签的地址.以下是查询.

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