Issue
I would like to create a database request which returns my Objects from a Class group by Year/Month.
The idea is to get via JPA / Hibernate a List<Object[]>
theList:
Object[0]
= a list from my objects
Object[1]
= the year/month
Any idea how I should create the SQL statement for this?
I´ve tried this:
SELECT count(m), m, month (m.myField) AS timeValue, year(m.myField) AS yearValue
FROM MyClass m
GROUP BY m, month (m.myField), year(m.myField)
Solution
Apparently you want all objects, just grouped, but the SQL concept of grouping always also means aggregating. Just read all the data then and group it into a hash map with java.
Answered By - Christian Beikov
Answer Checked By - Timothy Miller (JavaFixing Admin)