milosmns
milosmns

Reputation: 3793

How do I find all distinct values for each record (identified by ID) in BigQuery?

Data

This is an import from another place, so my data in BigQuery looks something like this:

order_id | owner_pk | owner_sk | other_properties | currency

Notes

Problem

I'd like to find if there are orders (order_id) coming from the same owner (PK+SK) that have different (distinct?) currency values. I don't need the actual orders, true/false is ok.

Any help with querying for that is appreciated! :)

Upvotes: 0

Views: 159

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269493

You can use aggregation. I would return the currencies as well as the number:

select owner_pk, owner_sk,
       array_agg(distinct currency) as currencies,
       count(distinct currency) as num_currencies
from t
group by owner_pk, owner_sk;

Upvotes: 1

Related Questions