String daily = "to_char(query_Date,'dd')";// 自然日
String weekly = "to_char(query_Date,'iw')";// 自然周
String monthly = "to_char(query_Date,'mm')";// 自然月
String yearly = "to_char(query_Date,'yyyy')";// 自然年
// 按年统计,则直接确定年份即可
if (frequencey.equalsIgnoreCase("yearly"))//
cq.addProjection(Projections.sqlGroupProjection(yearly, yearly,
new String[] { yearly },
new Type[] { Hibernate.STRING }));
// 按月份,需要在年份的基础上做
else if (frequencey.equalsIgnoreCase("monthly")) {
cq.addProjection(Projections.sqlGroupProjection(yearly, yearly,
new String[] { yearly },
new Type[] { Hibernate.STRING }));
cq.addProjection(Projections.sqlGroupProjection(monthly,
monthly, new String[] { monthly },
new Type[] { Hibernate.STRING }));
}
// 按周,需要在年份的基础上做
else if (frequencey.equalsIgnoreCase("weekly")) {
cq.addProjection(Projections.sqlGroupProjection(yearly, yearly,
new String[] { yearly },
new Type[] { Hibernate.STRING }));
cq.addProjection(Projections.sqlGroupProjection(weekly, weekly,
new String[] { weekly },
new Type[] { Hibernate.STRING }));
}
// 按天,需要在年份、月或者年周的基础上做
else if (frequencey.equalsIgnoreCase("daily")) {
cq.addProjection(Projections.sqlGroupProjection(yearly, yearly,
new String[] { yearly },
new Type[] { Hibernate.STRING }));
cq.addProjection(Projections.sqlGroupProjection(monthly,
monthly, new String[] { monthly },
new Type[] { Hibernate.STRING }));
cq.addProjection(Projections
.sqlGroupProjection(daily, daily,
new String[] { daily },
new Type[] { Hibernate.STRING }));
}