DEV Community

Judy
Judy

Posted on

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

Top comments (0)