mysql - How to aggregate (sum) values over month in jasperreports (each month should be the sum of all month before) -
mysql - How to aggregate (sum) values over month in jasperreports (each month should be the sum of all month before) -
i want study jasperreports aggregates our contracts on month adding new , old contracts month. database mysql database. select illustration info below:
select month(contract_date), amount contracts year(contract_date)=2013 grouping month(contract_date) 1.1.2013 300 1.1.2013 500 1.2.2013 250 1.3.2013 250
now get:
1 800 2 250 3 250 ...
but have:
1 800 2 1050 3 1300 ...
so each month contains amount of month before.
i dont mind if can in sql or jasperreports/ireport, solution welcome. there way can this?
mysql doesn't have ctes inconvenient, view in pinch.
create view monthlytotals select month( contractdate ) contractmonth, sum( contractqty ) totalqty contracts grouping contractmonth;
now can bring together view itself, maintaining running total of month , previous months:
select t1.contractmonth, t1.totalqty, sum( t2.totalqty ) runningtotal monthlytotals t1 bring together monthlytotals t2 on t2.contractmonth <= t1.contractmonth grouping t1.contractmonth;
the output matches desired output, seen @ sql fiddle.
mysql sql jasper-reports aggregate
Comments
Post a Comment