簡體   English   中英

在 Bigquery 中使用 JOIN 進行計數

[英]Counting using JOIN in Bigquery

我有兩組 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 的總數。

也許你只是想要一個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

只需離開加入兩者

 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