Reputation: 673
I have a MySQL database, and I intend to implement a Group By
query using Spring Data. (I'm really new to Spring Data)
i.e.
Select Department, Count(*) From Employee Group By Department.
So far I've seen a lot of solutions here using MongoDb, but nothing on MySQL. I know you can use @Query
annotation, but is there any other way I can achieve this?
Upvotes: 0
Views: 1069
Reputation: 81882
For specifying queries with Spring Data you have the following options:
Use one of the methods in the predefined interfaces like CrudRepository
or JpaRepository
. None of those does any grouping by.
Use Query Methods where the name of the method defines the query. There is no keyword for group by
either.
Use a @Query
annotation. This works, but you want an alternative.
You can write a custom implementation. But why would you if you can achieve the same with the @Query
annotation?
While there is technically an alternative, you probably want to use @Query
in this case.
Upvotes: 2