简体   繁体   中英

Counting using JOIN in Bigquery

I have two sets A and B. I want to display counts of A as well as counts on A (intersection) B using condition X.

在此处输入图像描述

Code I am using

SELECT COUNT(A) as total, COUNT(IF (condition_X)) as chg
FROM A
FULL OUTER JOIN B
ON JOIN KEY Y

I am able to get the intersection but not the count of A in total.

Perhaps you just want a cross join ?

select *
from (select count(*) as cnt_a from a) a cross join
     (select count(*) as cnt_b
      from a join
           b
           on y
      where condition
     ) b

Simply left join the two

 Select count(A.id=B.id), 
   count(A.id) 
   from A left join B on A.id=B.id
    where condition='x' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM