Grouping
Definition
The grouping method allows you to add the GROUPING function to the query.
The GROUPING function returns 0 if the argument is a member of the current grouping set and 1 otherwise.
tip
The use of this method is recommended in statements that involve the GROUPING SETS, CUBE, or ROLLUP subclauses.
Available methods calling from a KColumn or a KTableColumn
1. grouping()
It does not receive any parameters.
info
The KColumn or KTableColumn that invokes the method will be the one supplied to the GROUPING function.
Example
Java code:
k
.select(
count(),
APP_USER.ROLE_ID.grouping()
)
.from(APP_USER)
.groupBy(APP_USER.ROLE_ID)
.multiple();
SQL generated:
SELECT
COUNT(*),
GROUPING(au.role_id)
FROM app_user au
GROUP BY au.role_id
Parameters:
- None
Available methods calling from the KFunction class
1. grouping(KColumn kColumn)
- kColumns: is the expresion that will be supplied to the
GROUPINGfunction.
Among the possible values are:KTableColumn,KColumn.
To use this way, you need to import the static functions as follows:
import static com.myzlab.k.KFunction.*;
Example
Java code:
k
.select(
count(),
grouping(APP_USER.ROLE_ID)
)
.from(APP_USER)
.groupBy(APP_USER.ROLE_ID)
.multiple();
SQL generated:
SELECT
COUNT(*),
GROUPING(au.role_id)
FROM app_user au
GROUP BY au.role_id
Parameters:
- None