//求两个日期之间的数据之和 //2011/03/16为起始日,2011/09/15为结束日 //没一个月为一个梯度,也就是3.16-4.15,4.16-5.15,... //数据: 日期 金额 2011/03/16 20 2011/03/17 30 2011/04/14 50 2011/04/15 50 2011/04/16 10 2011/04/17 20 2011/05/14 30 2011/05/15 40 2011/05/20 10 2011/06/17 20 2011/06/18 30 //结果: 月份 总金额 2011/04 150 2011/05 100 2011/06 10 2011/07 50 //这个问题的关键是将如何按照日期区间来统计金额 //如果我们这么想,就能够将问题简单化: //也就是进行分组查询,将日期进行对比,分别进行统计,然后再连接到一起: //解法一: select '2011/04' month,sum(val) sum_sal from t where dt between to_date('2011/03/16','yyyy/mm/dd') and to_date('2011/03/16','yyyy/mm/dd')+30 union all select '2011/05',sum(val) from t where dt between to_date('2011/04/16','yyyy/mm/dd') and to_date('2011/04/16','yyyy/mm/dd')+30 union all select '2011/06',sum(val) from t where dt between to_date('2011/05/16','yyyy/mm/dd') and to_date('2011/05/16','yyyy/mm/dd')+30 union all select '2011/07',sum(val) from t where dt between to_date('2011/06/16','yyyy/mm/dd&#