i havent been able to find an answer to this but I think it should be possible to do this with only one query with BigQuery - i'm looking for something close to this, even with approximate results.
let's say i have a table that looks like this, with one column called myValue
====
myValue
====
foo |
bar |
bar |
baz |
i would like to be able to have a single query that results in a column next to it that has the distinct counts of myValue, on every row.
=======|=====================|
myValue|myNewCounts |
=======|=====================|
foo |[foo:1, bar:2, baz:1]
bar |[foo:1, bar:2, baz:1]
bar |[foo:1, bar:2, baz:1]
baz |[foo:1, bar:2, baz:1]
I know that you can use ARRAY_AGG(distinct) to get the distinct values on every row, but I haven't been able to find a way to also get the counts as well on every row, even in an approximate fashion.
It's important that this be done in a single query - I could obviously have a separate query that calculates the distinct counts and then join that back to this table, but im trying to do this in one query.
one would think - that in a columnar database - returning myValue and myNewCounts in one pass should be doable somehow....