If I have a table like this in BigQuery
id success ------------- 01 true 01 true 02 false 02 true I would like to end up with this:
id true false -------------------- 01 2 0 02 1 1 I've got this but I wondered if there was a more elegant way to do it?
SELECT t1.id, ( SELECT count(*) FROM `my_table` t2 WHERE t2.success = true and t2.id = t1.id ) as trueCount, ( SELECT count(*) FROM `my_table` t3 WHERE t3.success = false and t3.id = t1.id ) as falseCount FROM `my_table` t1 GROUP BY id 