简体   繁体   English

在 Bigquery 中使用 JOIN 进行计数

[英]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.我有两组 A 和 B。我想使用条件 X 显示 A 的计数以及 A(交叉点)B 的计数。

在此处输入图像描述

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.我能够得到交叉点,但不能得到 A 的总数。

Perhaps you just want a cross join ?也许你只是想要一个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' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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