
Grouping behavior is triggered using the query option apply
and the groupby
keyword. This keyword specifies the grouping properties, a comma-separated list of one or more single-valued property paths that is enclosed in parentheses. The same property path SHOULD NOT appear more than once; redundant property paths MAY be considered valid, but MUST NOT alter the meaning of the request.
Simply enclose the group properties with parentheses. For example, to group the orders by CardCode
, DocEntry
, send a request like:
GET /b1s/v1/Orders?$apply=groupby((CardCode, DocEntry))
Or
/b1s/v1/Orders?$apply=groupby((Orders/CardCode, Orders/DocEntry))
On success, the response is like:
The equivalent SQL on HANA is:
SELECT T0."CardCode", T0."DocEntry" FROM "ORDR" T0 GROUP BY T0."CardCode", T0."DocEntry"
SL also supports to combine grouping with aggregation. For example, to aggregate the DocNum
property on grouping CardCode
, send a request like:
GET /b1s/v1/Orders?$apply=groupby((CardCode), aggregate(DocNum with sum as TotalDocNum))
On success, the response is like:
The equivalent SQL on HANA is:
SELECT T0."CardCode", SUM(T0."DocNum") AS "TotalDocNum" FROM "ORDR" T0 GROUP BY T0."CardCode"
SL allows to filter before grouping. These two operations are separated by a forward slash to express that they are consecutively applied. For example, to filter before grouping with aggregation method, send a request like:
GET /b1s/v1/Orders?$apply=filter(Orders/CardCode eq 'c001')/groupby((CardCode), aggregate(DocNum with sum as TotalDocNum))
On success, the response is like:
The equivalent SQL on HANA is:
SELECT T0."CardCode", SUM(T0."DocNum") AS "TotalDocNum" FROM "ORDR" T0 WHERE T0."CardCode" = 'c001' GROUP BY T0."CardCode"
[Note] The filter
option can also be specified as below, which is functionally equivalent.
GET /b1s/v1/Orders?$apply=groupby((CardCode), aggregate(DocNum with sum as TotalDocNum))&$filter=(Orders/CardCode ne 'c001')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
31 | |
8 | |
5 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |