Reputation: 809
I have this function
i need to do that in sql (hibernate or mysql) or a java function that interpert the array of results
i need a consequetive results fort groupe by day
select DAY(prop.docCreationDate), count(prop.docfullName) from propCode.propClass as prop where prop.docCreationDate >= '" + startDate + " 00:00:00' and prop.docCreationDate <= '" + endDate + " 23:59:59' GROUP BY DAY(prop.docCreationDate)"
i have this entitie count in my table
2012-10-05 3
2012-10-06 0
2012-10-07 7
2012-10-08 13
2012-10-09 9
2012-10-10 0
2012-10-11 0
2012-10-12 3
the request return me this values
5 3
7 7
8 13
9 9
12 3
in this way i loose three lignes that have 0 as value, i need a request that return me this
5 3
6 0
7 7
8 13
9 9
10 0
11 0
12 3
Upvotes: 1
Views: 225
Reputation: 13272
I'm assuming that in your propClass
table you have multiple entries per day with document path names. Since the entries that you have provided are already almost what you need, except for a day conversion, and it's not matching the query used.
Considering this, the entries mentioned by you are the total number of documents per day and I assume that for the missing days you inserted the 0 values. If so, you can use time_intervals
temporary table like the one mentioned here. And then you should be able to do something like:
call interval_between('"+ startDate +"', '" + endDate + "', 'DAY', 1);
select day(ti.interval_from), count(prop.docfullName) from time_intervals ti left join propClass as prop
on prop.docCreationDate>=ti.interval_from AND prop.docCreationDate < ti.interval_from + INTERVAL 1 DAY
where ti.interval_from>='"+ startDate +"' and ti.interval_from < '" + endDate + "'
group by ti.interval_from;
Using native queries you can call the above two statements from hibernate.
Tested with SqlFiddle.
Upvotes: 2