首页 > 解决方案 > 计算左联合表中的非空值

问题描述

直接从左联合表上的 select 语句(不使用 where)计算非空值

count(*) as comments需要这个来提供非空值的计数。此外,inner join这不是一个解决方案,因为它不包括在count(distinct (t1.postId)) as no_of_content

select  t1.tagId as tagId, count(distinct (t1.postId)) as no_of_content, count(*) as comments
from  content_created as t1
left join comment_created as t2 
on t1.postId=t2.postId
where   
(   (t1.tagId = "S2036623" )
 or  (t1.tagId = "S97422" )
)
group BY 1

标签: mysqlgoogle-cloud-platformgoogle-bigquery

解决方案


虽然发布示例数据可能会帮助我们更多地回答这个问题,但您可以将您的计数功能更新为 -

COUNT(CASE WHEN postId IS NULL THEN 1 END) as comments

推荐阅读