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)
| STATUS | sups |
| 10 | |
| 20 | | SNO | SNAME | CITY |
|---|
| S1 | Smith | London | | S4 | Clark | London |
|
| 30 | | SNO | SNAME | CITY |
|---|
| S3 | Blake | Paris | | S5 | Adams | Athens |
|
group with inverted attr_list
group($S, ~{STATUS}, sups)
| STATUS | sups |
| 10 | |
| 20 | | SNO | SNAME | CITY |
|---|
| S1 | Smith | London | | S4 | Clark | London |
|
| 30 | | SNO | SNAME | CITY |
|---|
| S3 | Blake | Paris | | S5 | Adams | Athens |
|
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).