Supposing I have the following rows:
VARIABLENAME YYYYMM XXXXYY DATAOBS
variable_1 | 201101 | 111100 | 20
variable_2 | 201101 | 111100 | 20
variable_1 | 201102 | 111100 | 30
variable_2 | 201102 | 111100 | 30
variable_1 | 201101 | 222211 | 20
variable_2 | 201101 | 222211 | 20
variable_1 | 201102 | 222211 | 30
variable_2 | 201102 | 222211 | 30
I would like to know how to get the result:
VARIABLENAME YYYYMM XXXXYY DATAOBS
variables_1and2 | 201101 | 111100 | 40
variables_1and2 | 201102 | 111100 | 60
variables_1and2 | 201101 | 222211 | 40
variables_1and2 | 201102 | 222211 | 60
where all the DATAOBS in rows containing variable_1 and variable_2 within each respective YYYYMM within in each respective XXXXYY are added and placed in a new row, variables_1and2, still within their respective YYYYMM and respective XXXXYY.
If it’s necessary to know, there are several hundred different YYYYMM and XXXXYY in the actual data I’m dealing with.
Thanks in advance!
It sounds like you just want
If the intention is to insert these rows back into your table, you’d need an
INSERTOf course, it would be very unusual for it to make sense to store both detail and aggregate data in the same table. That would generally be a poor design.