I have an SQL table:
@Table(name = "population_table")
public class Population {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String country;
private String state;
private String area;
private String population;
}
I want to get a count, grouping by country and state with the output class being List of Count:
private static class Count {
private String country;
private String state;
private long count;
}
I know the query is
SELECT country, state, Count(*)
FROM population_table
GROUP BY country, state
But I want to do this using JPA Specification. How can I achieve this using JPA Specification in spring boot?