在bigquery中使用join进行sql计数

l0oc07j2  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(323)

我有两套a和b。我想使用条件x显示a的计数以及a(交叉点)b的计数。

我使用的代码

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

我能到达十字路口,但总的数不到a。

zdwk9cvp

zdwk9cvp1#

也许你只是想要一个 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
anauzrmj

anauzrmj2#

简单的左键连接两个

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

相关问题