Reputation: 5129
I want to transform a sql query in JPA.
SELECT status, count(*)
FROM abc
WHERE type='XXX'
GROUP BY status
I need something in a JPARepository with sql.
@Repository
public interface ABCRepository extends JpaRepository<abc, Long> {
long countByStatusAndType(final A type, final B status);
}
Is it Possible?
Upvotes: 0
Views: 2641
Reputation: 2775
Firstly, create class containing parameters status
and count
for handling results, then create method in repository with query
@Query("SELECT status, count(*) as count FROM abc WHERE type=:type GROUP BY status")
List<CustomResultClass> countByStatus(String type);
Upvotes: 1