Bookmark Topic Watch Topic
  • New Topic

Using SUM with group By in Java  RSS feed

Kumar Val
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Class Status {
private long passCount;
private long failCount;
private Date examDate;

Above class informs pass,fail count for an exam Date.There are different schools in a Town. Each school will have its own data in a different database. The exam dates might be different for diferent schools. I have to calculate all the passcount, fail count in the town group by examDate for a given date range. For example if the Date range is 08/20/2006- 08/10/ will be like below ( Output details are at Town level, not at the school level)

Datepass fail
08/20/2006 50 10
08/18/2006 40 07
08/17/2006 30 07
08/16/2006 20 01
08/15/200620 02
08/10/2006 5 1

Town has 10 schools. Since each school has data in its own database server(All servers are oracle. But IPAddress,username and password are different). I have to make different call to each database server to get arraylist of status objects group by examDate. For example school1 might return below array list
Datepass fail
08/20/2006 10 01
08/01/2006 30 01

In the same way each school will return its own arraylist of status objetcs grouped by examdate from seperate database server. Now i have to disply a list of status objects by calculating sum of pass, fail from arraylists of status objects for each school.Each school will have its own exam dates. For example on 08/20/2006 only school1,school2 have exams.

If there was only one database i would have done it in single query with group by clause on examDate.
Since there are different data bases, i have to get list of status objects from different schools. In side my java program i have to sum the pass, fail count for each school on a date. If there are 10 schools , i have to loop throught the arraylist of those schools and compare the examDates and calculate the sum of pass, fail counts. It requires lot of for loops and if loops..Is there any way to do it in a better way to improve the performance.
Ilja Preuss
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Crosspost, closing.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!