1

我有这个功能

我需要在sql(hibernate或mysql)或interpert结果数组的java函数中这样做

我需要一个连续的结果fort groupe by day

从 propCode.propClass 中选择 DAY(prop.docCreationDate), count(prop.docfullName) 作为 prop.docCreationDate >= '" + startDate + " 00:00:00' 和 prop.docCreationDate <= '" + endDate + " 23:59:59' 按天分组(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  
4

1 回答 1

2

我假设在您的propClass表格中,您每天有多个带有文档路径名称的条目。由于您提供的条目已经几乎是您需要的,除了一天的转换,它与使用的查询不匹配。

考虑到这一点,您提到的条目是每天的文档总数,我假设您在缺失的日子里插入了 0 个值。如果是这样,您可以使用此处time_intervals提到的临时表。然后您应该能够执行以下操作:

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;

使用本机查询,您可以从 hibernate 调用上述两个语句。

SqlFiddle测试。

于 2012-10-23T11:58:51.550 回答