按最大值和字段进行OData筛选

按最大值和字段进行OData筛选,odata,Odata,数据集包含具有以下键的记录:userID、period和points 是否可以按期间和max点查询一条记录 示例场景 数据集 [ /* 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}, /* peri

数据集包含具有以下键的记录:userID、periodpoints

是否可以按
期间和max
点查询一条记录

示例场景

数据集

[
 /* 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},

如果要查询的实体集名为
PointHistory
,则可以使用中定义的
$apply
查询选项:

GET PointHistory?$apply=groupby((period),topcount(1,points))
这将按
期间
对记录进行分组,按
对每组中的记录进行排序,然后返回每组中最上面的记录