DEV Community

Judy
Judy

Posted on

2 1 1 1 1

Group and Summarize data, and align to the specified sequence #eg31

Below is temp_data table in Oracle database:

Image description
LETTER is the foreign key field, which points to temp_ref table’s LETTER field, whose order is specified by LETTER_SEQ field in the same table.

Image description
Task: Group temp_data table by the year and LETTER field, count records in each group, and align records to the cross product of the year and the LETTER; record CNT as null if no count value exists. Arrange years in the chronological order and the LETTER according to LETTER_SEQ. Below is the expected result:

Image description
Write the following SPL code:

Image description

A1, A2: Run the simple SQL to group and summarize temp_data table; and retrieve values of LETTER field in the specified order.

A3: Compute cross product of the year and the letter, and then associate the result with A1 through the foreign key. #1 is the 1st field.

Source

SPL open source address

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

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