I'm working with a BigQuery database table that holds history changes to different fields as separate events in a history table.
For example, take a table that has two fields:
Id | Food | Color |
---|---|---|
6 | Bacon | Red |
9 | Salad | Green |
Any changes to the values in this table would be output to a history table like:
History table
Change date | id | Field name | Field Value |
---|---|---|---|
17 Jan 2022 | 6 | Food | Steak |
19 Jan 2022 | 9 | Color | Yellow |
21 Jan 2022 | 6 | Color | Blue |
How can I transform the 'history' table so that it flattens the change values into a single inherited view of change state as shown below?
Transformed table
id | Date | Food | Color |
---|---|---|---|
6 | 17 Jan 2022 | Steak | Red |
9 | 19 Jan 2022 | Salad | Yellow |
6 | 21 jan 2022 | Steak | Blue |