I have a table in this form:
TIME TYPE COUNT
00:01 DOG 4
00:04 CAT 5
00:07 DOG 2
00:30 BIRD 1
01:04 DOG 2
01:30 BIRD 3
01:40 DOG 1
02:01 BIRD 4
I do a query like this that joins the sum of COUNT of each TYPE based on hour:
select HOUR(`TIME`), `TYPE`, sum(`COUNT`)
from `table`
where `TYPE` = 'DOG'
group by HOUR(`TIME`)
FULL JOIN
...(same query but... where `TYPE` = 'CAT')
ON hour...
FULL JOIN
...(same query again, but where `TYPE` = 'BIRD')
etc.
The purpose being to get a result like this:
HOUR DOG CAT BIRD
00 6 5 1
01 5 0 3
02 0 0 4
My question is: How can you do this without joins? I want a query to work for any distinct TYPE values that happen to the be in the table and are not known upfront, so the table would grow in columns foreach distinct TYPE.
Is this something that could be done with BigQuery script?