-
Lowest Competitor Price
-
Use of the following methods:
-
.aggregateBy() -
.sum() -
.count() -
.min() -
.max() -
.avg()
-
Code
Groovy
def qapi = api.queryApi()
def exprs = qapi.exprs()
def t1 = qapi.tables().productExtensionRows("Competition")
return qapi.source(t1, [t1.sku(), t1.Price])
.aggregateBy({ cols -> [cols.sku] },
{ cols -> [cols.sku, exprs.min(cols.Price).as("MinPrice")] })
.stream { it.collect { it } }
Result
|
sku |
MinPrice |
|---|---|
|
10000001 |
92 |
|
10000002 |
66 |
