4

Suppose I am querying a dataset called Sales with the following schema:

id (int) price (decimal) active (bit)

Using the $apply query option and the aggregate transformation of the OData v4 spec, what would be the syntax for finding the average price for only active Sales?

$apply supports both aggregation and filter transformations, but I can't figure out how to combine them or if you're even allowed to do so.

Thanks!

Ken
  • 1,830
  • 3
  • 20
  • 32

1 Answers1

3
$apply=filter(Status eq 1)/aggregate(price with average as averagePrice)

maybe you can refer the existing test:

https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/Aggregation/AggregationTests.cs

https://github.com/OData/WebApi/blob/master/OData/test/UnitTest/System.Web.OData.Test/OData/Query/ApplyQueryOptionTest.cs

Fan Ouyang
  • 2,132
  • 1
  • 11
  • 13
  • is there a way to get only top5 of the averageprice? I mean apply orderby>top to the results of aggregate – Nameless Dec 26 '17 at 10:52