← aggr operator page · clause/aggr/group_by/manual_ex_1
pandas ✅ · DuckDB ✅
aggr Me_1 := sum( Me_1 ) group by Id_1 , Id_2, over an Integer measure.
Aggregation, Example 1, with the manual's data points: "group by: the Data Points are grouped by the values of the specified Identifiers (groupingId). The Identifiers not specified are dropped in the result."
Id_3 is dropped, and the sums are 2, 8 and 9. Me_1 may be Integer, as the manual's ex_1.json writes it, or Number: Sum says "implementations may preserve the integer type for the resulting measure or component when all operand values are integer and the sum is computed in integer arithmetic".
DS_r := DS_1 [ aggr Me_1:= sum( Me_1 ) group by Id_1 , Id_2 ];
| Id_1 | Id_2 | Id_3 | Me_1 |
|---|---|---|---|
| 1 | A | XX | 0 |
| 1 | A | YY | 2 |
| 1 | B | XX | 3 |
| 1 | B | YY | 5 |
| 2 | A | XX | 7 |
| 2 | A | YY | 2 |
{
"datasets": [
{
"name": "DS_1",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 2 |
| 1 | B | 8 |
| 2 | A | 9 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "Id_2", "type": "String", "role": "Identifier"},
{"name": "Me_1", "type": ["Integer", "Number"], "role": "Measure"}
]
}
]
}