【问题标题】:OData filter by max value and fieldOData 按最大值和字段过滤
【发布时间】:2018-08-11 13:18:47
【问题描述】:

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

是否可以按periodma​​x 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},

【问题讨论】:

    标签: odata


    【解决方案1】:

    这可以通过OData Extension for Data Aggregation Version 4.0 中定义的$apply 查询选项实现,假设要查询的实体集名为PointHistory

    GET PointHistory?$apply=groupby((period),topcount(1,points))
    

    这将按period 对记录进行分组,按points 对每个组中的记录进行排序,然后返回每个组最上面的记录。

    【讨论】:

      猜你喜欢
      • 2019-11-09
      • 2017-02-16
      • 1970-01-01
      • 2016-04-03
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多