I have these tables:
Foods
| food_id | title |
| 1 | soy milk |
| 2 | banana |
| 3 | apple |
Nutrients
| food_id | nutrient_id | amount |
| 1 | n1 | 0.05 |
| 1 | n2 | 2 |
| 1 | n3 | 34 |
...
I need this:
| food_id | title | n1 | n2 | n3 |
| 1 | soy milk | 0.05 | 2 | 34 |
| 2 | banana | | | |
| 3 | apple | | | |
The column titles should be represented by whatever found in nutrient_id
column, not by actual strings "n1", "n2" etc. For example, if the nutrient id is "some-nutrient-123", then I want to see a column in results with the title "some-nutrient-123".
Struct
would also work.
I know all the joins, but can't wrap my head around this... how do I put the value of nutrient_id
into a column title or a Struct
key?