Builtin

group

group(a, {attr_list}, group_name)

A relation operator. Adds a new nested relation, named group_name, containing each attr in the attr list moved down from a.

Note: inverting the attr_list, i.e. ~{attr_list} makes group behave more like SQL's group by.

Examples

group
group($S, {SNO, SNAME, CITY}, sups)
STATUSsups
10
SNOSNAMECITY
S2JonesParis
20
SNOSNAMECITY
S1SmithLondon
S4ClarkLondon
30
SNOSNAMECITY
S3BlakeParis
S5AdamsAthens

group with inverted attr_list
group($S, ~{STATUS}, sups)
STATUSsups
10
SNOSNAMECITY
S2JonesParis
20
SNOSNAMECITY
S1SmithLondon
S4ClarkLondon
30
SNOSNAMECITY
S3BlakeParis
S5AdamsAthens

Note: this version gives the same results as above but behaves as expected if new attributes are added to the relation (and perhaps reads more easily).