And
Definition
The and
methods allows you to add the AND
operator to a HAVING
clause.
Available methods
1. and(
KCondition
kCondition)
- kCondition: which contains all the information about the condition that will be added to the
HAVING
clause with anAND
operator.
2. and(
KRaw
kRaw)
- kRaw: is a raw content which will be added in the
HAVING
clause with anAND
operator.
Method hierarchy
The and
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"),
APP_USER.EMAIL.countDistinct().as("distinctEmail"),
toChar(APP_USER.CREATED_AT, "YYYY").as("year")
)
.from(APP_USER)
.groupBy(raw("year"))
.having(count().greaterThan(120))
.and(APP_USER.EMAIL.countDistinct().greaterThan(70))
.multiple();
SQL generated:
SELECT
COUNT(*) AS "all",
COUNT(DISTINCT au.email) AS "distinctEmail",
TO_CHAR(au.created_at, ?1) AS "year"
FROM app_user au
GROUP BY year
HAVING COUNT(*) > ?2
AND COUNT(DISTINCT au.email) > ?3
Parameters:
- ?1: "YYYY
- ?2: 120
- ?3: 70
Example: KRaw
Java code:
k
.select(
count().as("all"),
APP_USER.EMAIL.countDistinct().as("distinctEmail"),
toChar(APP_USER.CREATED_AT, "YYYY").as("year")
)
.from(APP_USER)
.groupBy(raw("year"))
.having(raw("COUNT(*) > 120"))
.and(raw("COUNT(DISTINCT au.email) > 70"))
.multiple();
SQL generated:
SELECT
COUNT(*) AS "all",
COUNT(DISTINCT au.email) AS "distinctEmail",
TO_CHAR(au.created_at, ?1) AS "year"
FROM app_user au
GROUP BY year
HAVING COUNT(*) > 120
AND COUNT(DISTINCT au.email) > 70
Parameters:
- ?1: "YYYY