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 aKCountFunctionthat allows adding conditions to the base query and aKColumnor aKTableColumnwhich will be supplied to thecountmethod.countDistinctBy(String jdbc, KCountFunction<KFrom, KQuery> kCountFunction, KColumn kColumn): Receives the name of datasource connection to which you need to connect, aKCountFunctionthat allows adding conditions to the base query and aKColumnor aKTableColumnwhich will be supplied to thecountmethod.
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