@pmroz has done most of the work, which one can add to:
NamesDefaultToHere(1);
dt = New Table( "Subjects",
Add Rows( 9 ),
New Column( "Student",
Character( 16 ),
"Nominal",
Set Values( {"A", "A", "A", "A", "A", "A", "A", "A", "A"} )
),
New Column( "Sequence",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 4, 5, 2, 4, 6, 2, 1] )
),
New Column( "Subject",
Character( 16 ),
"Nominal",
Set Values(
{"Economics", "Science", "Physics", "Math", "Science", "Chemistry", "Science", "Math", "Social"}
)
)
);
// Make any row selection (in this case, the 'blue' rows)
dt << selectRows({2, 4, 5, 7, 8 });
// Get key list from the current row selection
subjectVals = Column(dt, "Subject")[dt << getSelectedRows];
key_list = AssociativeArray(subjectVals) << getKeys;
// Build associative arrays from current key list
subject_aa = associative array();
for (i = 1, i <= nitems(key_list), i++,
found_rows = dt << get rows where(as column(dt, "Subject") == key_list[i]);
subject_aa[key_list[i]] = found_rows;
);
show(subject_aa);
Right click on the JSL key words in the editor and do 'Help Scripting Index' to get more information.
Using your example, once you have the associative arrays the specification of the thee tables you say you want was unclear to me.