DEV Community

Judy
Judy

Posted on

3 1 1 1 1

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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more