← aggr operator page · clause/aggr/attribute_role/attribute_next_to_measure
pandas ✅ · DuckDB ✅
aggr Me_1 := sum ( Me_1 ), attribute At_1 := max ( Me_1 ) group by Id_1: a new attribute next to the aggregated measure.
Aggregation: "It is possible to specify the role of the calculated Component among measure, attribute, or viral attribute", and "The Attributes calculated through the aggr clauses are maintained in the result".
Per Id_1, with Id_2 dropped, the sums Me_1 = 6 and 7 and the maxima At_1 = 5 and 4, an Integer Attribute, as for max "For numeric operands, the result has the same type as the operand"; Me_1 may be Integer or Number, by the integer rule of Sum. The Me_1 item keeps a Measure in the result: Attribute without measure leaves it out.
DS_r := DS_1 [ aggr Me_1 := sum ( Me_1 ), attribute At_1 := max ( Me_1 ) group by Id_1 ];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 1 |
| 1 | B | 5 |
| 2 | A | 3 |
| 2 | B | 4 |
{
"datasets": [
{
"name": "DS_1",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 6 | 5 |
| 2 | 7 | 4 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "Me_1", "type": ["Integer", "Number"], "role": "Measure"},
{"name": "At_1", "type": "Integer", "role": "Attribute"}
]
}
]
}