数据集包含具有以下键的记录:userID,period和points。
是否可以按period
和max points
查询一条记录。
示例场景
数据集
[
/* period: 2016-01-01 */
{ userID: 1, period: '2016-01-01', points: 100},
{ userID: 1, period: '2016-01-01', points: 200},
{ userID: 1, period: '2016-01-01', points: 300},
/* period: 2016-01-02 */
{ userID: 1, period: '2016-01-02', points: 50},
{ userID: 1, period: '2016-01-02', points: 70},
{ userID: 1, period: '2016-01-02', points: 10},
/* period: 2016-01-03 */
{ userID: 1, period: '2016-01-03', points: 80},
{ userID: 1, period: '2016-01-03', points: 20},
{ userID: 1, period: '2016-01-03', points: 0},
]
查询结果:
这些是所需的查询结果。每个期间一个记录和该期间的最大点数
{ userID: 1, period: '2016-01-02', points: 300},
{ userID: 1, period: '2016-01-03', points: 70},
{ userID: 1, period: '2016-01-04', points: 80},
这可以使用$apply
中定义的OData Extension for Data Aggregation Version 4.0查询选项,假设要查询的实体名为PointHistory
:
GET PointHistory?$apply=groupby((period),topcount(1,points))
这将按period
对记录进行分组,按points
对每组中的记录进行排序,然后返回每组最高记录。