- DocumentDB 教程
- DocumentDB - 首页
- DocumentDB - 简介
- DocumentDB - 优点
- DocumentDB - 环境设置
- DocumentDB - 创建帐户
- DocumentDB - 连接帐户
- DocumentDB - 创建数据库
- DocumentDB - 列出数据库
- DocumentDB - 删除数据库
- DocumentDB - 创建集合
- DocumentDB - 删除集合
- DocumentDB - 插入文档
- DocumentDB - 查询文档
- DocumentDB - 更新文档
- DocumentDB - 删除文档
- DocumentDB - 数据建模
- DocumentDB - 数据类型
- DocumentDB - 限制记录
- DocumentDB - 记录排序
- DocumentDB - 索引记录
- DocumentDB - 地理空间数据
- DocumentDB - 分区
- DocumentDB - 数据迁移
- DocumentDB - 访问控制
- DocumentDB - 数据可视化
- DocumentDB 有用资源
- DocumentDB - 快速指南
- DocumentDB - 有用资源
- DocumentDB - 讨论
DocumentDB - 记录排序
Microsoft Azure DocumentDB 语言 SQL 支持对 JSON 文档执行查询。您可使用查询中的 ORDER BY 子句对集合中的文档根据数字和字符串进行排序。该子句可包括可选的 ASC/DESC 参数以指定检索结果的顺序。
我们来看看以下有 JSON 文档的示例。
{
"id": "Food Menu",
"description": "Grapes, red or green (European type, such as Thompson seedless), raw",
"tags": [
{
"name": "grapes"
},
{
"name": "red or green (european type"
},
{
"name": "such as thompson seedless)"
},
{
"name": "raw"
}
],
"foodGroup": "Fruits and Fruit Juices",
"servings": [
{
"amount": 1,
"description": "cup",
"weightInGrams": 151
},
{
"amount": 10,
"description": "grapes",
"weightInGrams": 49
},
{
"amount": 1,
"description": "NLEA serving",
"weightInGrams": 126
}
]
}
以下是按降序对结果进行排序的 SQL 查询。
SELECT f.description, f.foodGroup, f.servings[2].description AS servingDescription, f.servings[2].weightInGrams AS servingWeight FROM f ORDER BY f.servings[2].weightInGrams DESC
执行上述查询时,您将收到以下结果。
[
{
"description": "Grapes, red or green (European type, such as Thompson
seedless), raw",
"foodGroup": "Fruits and Fruit Juices",
"servingDescription": "NLEA serving",
"servingWeight": 126
}
]
广告