Count Distinct By
Definition
The countDistinctBy
method allows you to count the number of unique values in the column or expression of a table that meet the given conditions.
Available methods
countDistinctBy(KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn)
: Receives aKCountFunction
that allows adding conditions to the base query and aKColumn
or aKTableColumn
which will be supplied to thecount
method.countDistinctBy(String jdbc, KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn)
: Receives the name of datasource connection to which you need to connect, aKCountFunction
that allows adding conditions to the base query and aKColumn
or aKTableColumn
which will be supplied to thecount
method.
Example: KCountFunction, KColumn
Java code:
final Long totalRecords =
languageRepository.countDistinctBy(
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L)),
LANGUAGE.ID
);
SQL generated:
SELECT COUNT(DISTINCT la.id)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12
Example: String, KCountFunction, KColumn
Java code:
final Long totalRecords =
languageRepository.countDistinctBy(
K.JDBC_LEGACY,
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.gt(12L)),
LANGUAGE.ID
);
SQL generated:
SELECT COUNT(DISTINCT la.id)
FROM auth.language la
WHERE la.id > ?1
Parameters:
- ?1: 12