BigQuery/SQL: How do I join two tables and use a column value as column name?
问题 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 | | | | Struct would also work. I know all the joins, but can't wrap my head around this... how do I put nutrient_id into a column title or a Struct key? 回答1: If you have a fixed list of