Я хочу найти всех кандидатов с максимальным количеством голосов в конкретном городе. Я пробовал этот следующий запрос, но он не работает. Моя таблица mysql называется «Кандидаты», а имя моего класса - «Кандидат».
@Query(value= "select c.name, c.city, max(c.votecount) from Candidate c group by c.city",nativeQuery = true)
List<Candidate> showResults();
Вот мой класс Кандидат pojo:
@Entity
@Table(name="candidates")
public class Candidate {
public Candidate() {}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name="name")
private String name;
@Column(name="vin")
private int vin;
@Column(name="city")
private String city;
@Column(name="votecount")
private int votecount;
public int getVotecount() {
return votecount;
}
public void setVotecount(int votecount) {
this.votecount = votecount;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVin() {
return vin;
}
public void setVin(int vin) {
this.vin = vin;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Candidate(Long id, String name, int vin, String city, int votecount) {
super();
this.id = id;
this.name = name;
this.vin = vin;
this.city = city;
this.votecount = votecount;
}
Использование почтальона, чтобы увидеть мой вывод , я получаю это сообщение:
"message": "could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"