Reputation: 103
I have the following query
select 123 as user_id, "[\"A\",\"B\",\"C\"]" as category
which generates this data:
user_id category
123 ["A","B","C"]
What I would like to get from this data is:
user_id category
123 A
123 B
123 C
How could I do it?
Upvotes: 0
Views: 117
Reputation: 12274
Use below.
WITH sample_data AS (
select 123 as user_id, "[\"A\",\"B\",\"C\"]" as category
)
SELECT user_id, category
FROM sample_data, UNNEST(JSON_VALUE_ARRAY(category)) category;
Upvotes: 1