Generally intragroup inter-row calculations are handled with window functions or report scripts. But the code is rather complicated. Instead, you can use esProc to assist reporting tools in dealing with them. Below is such an example.
Database table sample has three fields, among which id is the grouping field. You need to design a grouped table where id is the grouping field and the other fields holding detail data include v1, v2 and the computed field crossline.
crossline will be calculated like this: v1+v2+previous v1+previous v2. Below is the original data:
esProc code for data preparation:
A1: Query the database and create an additional field with constant values for later use.
A2: Group A1 by id, modify crossline values for each group and combine groups of data together. Result is as follows:
A3: Return A2’s result to the reporting tool. esProc provides JDBC interface outward to be identified by a reporting tool as a normal database.