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:
   
 
You can refer to How to Call an SPL Script in Java to learn how to call an SPL script in a Java application.
 
SPL Official Website 👉 https://www.esproc.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.esproc.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/sxd59A8F2W
Youtube 👉 https://www.youtube.com/@esProc_SPL
 
            
        