mercredi 25 février 2015

Adding a column to aggregated data where new value only applies to a subset of the aggregation


Having trouble explaining this.


I have a table like this:


Label | Value

A | 3

B | 1

C | 4


And another like this:


Label | Value | ID

A | 1 | ID1

A | 1 | ID2

C | 4 | ID3


I need to add the ID column to the first table, splitting some rows according to the Value in the second table. Resulting in this:


Label | Value | ID

A | 1 | ID1

A | 1 | ID2

A | 1 | NULL

B | 1 | NULL

C | 4 | ID3


If the Label and Value columns were identical for both tables, I could easily do "join table2 ON table1.Label=table2.Label and table1.Value=table2.Value" but the unaggregation aspect of this is throwing me off.


Apologies if this is worded poorly. Thanks.





Aucun commentaire:

Enregistrer un commentaire