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,881
  • 13
  • 67
  • 93

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