Answer the question
In order to leave comments, you need to log in
How to add sql count to Map?
Task: read books by genre and bring them out.
I can't count them correctly. At first I tried to just count the number, but here is the problem.
public List<Integer> task4() {
Session session = this.sessionFactory.getCurrentSession();
String sql = "SELECT book.genre, COUNT(book.genre) AS counter FROM book book GROUP BY genre";
SQLQuery query = session.createSQLQuery(sql);
query.addEntity(Book.class);
// List<Integer> task4List = session.createQuery("SELECT book.genre, COUNT(book.genre) AS counter FROM book GROUP BY genre")
// .list();
List<Integer> task4List = query.list();
//Map<Integer,String> task4List = (Map<counter,genre >).
return task4List;
}
Answer the question
In order to leave comments, you need to log in
The key question is - for what purpose are you interested?
There are many options, offhand:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question