'How to count elements based on a unique value in BigQuery
Solution 1:[1]
Use below
select `desc`, count(distinct user_id) distinct_user_id
from (
select category as `desc`, user_id from your_table
union all
select segment, user_id from your_table,
unnest(split(segment, ';')) segment
)
where `desc` != ''
group by `desc`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mikhail Berlyant |