Inter-row Calculations - Calculate Store

Question

TEST table:
ID store
1  33
2  55
3  66
4  88
5  12

The expected query result:
ID   store   store1   store2
1   33   33   33
2   55   88   121
3   66   154   275
4   88   242   517
5   12   254   771

 

Answer

It’s complicated to handle calculations involving more than one data level. Since the data volume is small, we can retrieve all data out for processing in SPL (Structured Process Language):

A

1

$SELECT ID,store FROM TEST   ORDER BY ID

2

=A1.derive(store+store1[-1]:store1,store1+store2[-1]:store2)

A1: Retrieve data ordered by ID in SQL.

A2: Add store1 field and store2 field and use [-1] to reference the previous value. Here’s the final result:

 undefined

You can refer to How to Call an SPL Script in Java to learn how to call an SPL script in a Java application.