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

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

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay