Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery subsselect example (count and sum)

In google BigQuery I have done a simple query to get how many music someone has listened. What I need is to make a sum for all rows returned from the query below (some type of subquery)?

select count(1) cnt
from OF7.PETERV_TEST
where gender='F'
group by userId

Row f0_  
1   14   
2   1    
3   7    
4   18   
5   1    
6   4    
7   2    
8   2

expected result:

49
like image 835
Ferguson Avatar asked Sep 01 '25 10:09

Ferguson


1 Answers

you can use:

SELECT sum(cnt)
FROM
  (SELECT count(1) cnt
   FROM OF7.PETERV_TEST
   WHERE gender='F'
   GROUP BY userId )
like image 61
Pentium10 Avatar answered Sep 03 '25 11:09

Pentium10