How to distinct counting with Spring JPA Repository

Benimo picture Benimo · Jun 4, 2018 · Viewed 9.6k times · Source

How do I do a distinct counting with Spring Data JPA? I do not want to use the @Query annotation. The equivalent sql query would be:

SELECT COUNT(DISTINCT rack) FROM store WHERE id = 10001;

I tried by writing the following query, but it isn't working:

int countDistinctRackById();

Answer

Ilias Mentz picture Ilias Mentz · Jun 4, 2018

This should work :

Integer countDistinctRackById(Long id);