I have such data structure in BigQuery:
timestamp
fruit
properties (a nested and repeated field)
properties.species
properties.color
Sample data:
timestamp, fruit, properties struct: {properties.species, properties.color}
1 , apples, lobo , green
babo , green
2 , pears , mango , green
obo , green
3 , pears , bingo , yellow
I want to count fruit rows, which properties.color is green. So the answer for the example is 2.
Is there a better approach than counting timestamps? (You not always have a timestamp column in the data)
SELECT count(distinct timestamp) FROM table, unnest (properties) properties
WHERE properties.color = green