Skip to main content

Cross row computation in Java, SQL, Oracle or esProc?

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2012-02-15

In Java application development, ordered or cross-row computation based on database is oftenly involved, such as the last three, the previous one of the current record, the top five, the last but one, and the ranking of a certain record.

For instance,to find out the monthly growth rate of contract values for each sales man in 2012 in a Contract table. We need to firstly group by salesman, group by year within each group, group by month for each year and summarize, and lastly, perform the inter-row computation between the current month and its previous month.

With esProc script, it can be written as bellow:
1 $elect actualSale, Quantitu*Amount as sales, sellDate from contract where sell Date>=? And sellDate<=?; startTime, endTime
3 =A2.(;year,month(sellDate):month; actualSale,sum(sales):salesmonth))
4 =A3.(~.derive(salesMonth/salesMonth[-1]-1:rate))

We often use SQL to deal with it, but SQL does not offer any direct support for the algorithm related to sequence number. The problem is easy to solve since most ResultSet classes of JDBC support row number, and a few ones which doesn