How can I transform/pivot in Big Query:
From this:
solution sentiment groups feeling playing doing
I am good positive ['good', 'am'] 1 0 0
I am playing positive ['playing', 'am'] 0 1 1
She is running positive ['running', 'she] 0 1 0
He is not eating negative ['eating'] 1 0 1
To:
solution sentiment groups name value
I am good positive ['good', 'am'] feeling 1
I am good positive ['good', 'am'] playing 0
I am good positive ['good', 'am'] doing 0
I am playing positive ['playing', 'am'] feeling 0
I am playing positive ['playing', 'am'] playing 1
I am playing positive ['playing', 'am'] doing 1
She is running positive ['running', 'she] feeling 0
She is running positive ['running', 'she] playing 1
She is running positive ['running', 'she] doing 1
He is not eating negative ['eating'] feeling 1
He is not eating negative ['eating'] playing 0
He is not eating negative ['eating'] doing 1
I tried this way, but I am missing the name column...rest is looking fine.
SELECT solution, sentiment, groups, value
FROM table
LEFT JOIN UNNEST ([feeling, playing doing] ) AS value
I have tried like this to get the name column but doesn't work as it is giving wrong results:
SELECT solution, sentiment, groups, value, name
FROM table,
UNNEST (['feeling', 'playing','doing']) AS name
LEFT JOIN UNNEST ([feeling, playing, doing] ) AS value
Might need to UNNEST the name column in a nice way.
How do I create the name column?