Having
Definition
The having
methods allows you to add the HAVING
clause to the query.
Available methods
1. having(
KCondition
kCondition)
- kCondition: which contains all the information about the condition that will be added to the
HAVING
clause.
2. having(
KRaw
kRaw)
- kRaw: is a raw content which will be added in the
HAVING
clause.
Method hierarchy
The having
method can be used right after the following methods:
and the subsequent methods that can be called are:
and
,andNot
,or
,orNot
,window
,except
,exceptAll
,intersect
,intersectAll
,union
,unionAll
,orderBy
,limit
,offset
,fetch
,single
,multiple
Example: KCondition
Java code:
k
.select(
count().as("all"),
toChar(APP_USER.CREATED_AT, "YYYY").as("year")
)
.from(APP_USER)
.groupBy(raw("year"))
.having(count().greaterThan(120))
.multiple();
SQL generated:
SELECT
COUNT(*) AS "all",
TO_CHAR(au.created_at, ?1) AS "year"
FROM app_user au
GROUP BY year
HAVING COUNT(*) > ?2
Parameters:
- ?1: "YYYY
- ?2: 120
Example: KRaw
Java code:
k
.select(
count().as("all"),
toChar(APP_USER.CREATED_AT, "YYYY").as("year")
)
.from(APP_USER)
.groupBy(raw("year"))
.having(raw("COUNT(*) > 120"))
.multiple();
SQL generated:
SELECT
COUNT(*) AS "all",
TO_CHAR(au.created_at, ?1) AS "year"
FROM app_user au
GROUP BY year
HAVING COUNT(*) > 120
Parameters:
- ?1: "YYYY