ROW_NUMBER() / RANK()

  • Sequential/rank integer number

Window functions are only available in Analytics queries

Code

Groovy
def qapi = api.queryApi()
def orders = qapi.orders()

def t = qapi.tables().dataSource("Competition")

def wnd = qapi.exprs().window().allRows().partitionBy([t.sku]).sortBy([orders.ascNullsLast(t.Price)])

return qapi.source(t, [t.sku, t.Competitor, t.Price, wnd.rank().as("Rank"), wnd.rowNumber().as("RowNumber"),])
        .stream { it.toList() }

Result

RowNumberRank.png

See Also