DEV Community

Judy
Judy

Posted on

Multi combination condition grouping and aggregation #eg93

The table in the MS SQL database is as follows, where id is the keyword:

Image description
Now we need to first filter out records where both start_row and end_row are not null, and then calculate for each found record, finding those records in the table with IDs between start_row and end_row of this record, and where from or to is equal to the from field of this record, and then sum up the values of these records.

Image description
SPL code:

Image description

A1: Query the database through JDBC.

A2: Filter out records where both start_row and end_row are not null, i.e. the 5th and 6th records. && indicates logic AND.

A3: Create a new two-dimensional table based on A2. The first field is taken from ID, and the calculation method for the second field is to find the records in A1 whose ID is between start_row and end_row of the current record, and whose 'from' or 'to' is equal to the 'from' of the current record. Sum up the values of these records.

Open source SPL source address

Free Download

Top comments (0)