0

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?

emoleumassi
  • 4,345
  • 8
  • 55
  • 79

1 Answers1

1

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);
Tilekbekov Yrysbek
  • 2,545
  • 10
  • 17