mysql - 计算左联合表中的非空值
问题描述
直接从左联合表上的 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
解决方案
虽然发布示例数据可能会帮助我们更多地回答这个问题,但您可以将您的计数功能更新为 -
COUNT(CASE WHEN postId IS NULL THEN 1 END) as comments
推荐阅读
- python - 如何将线程用于拥抱面变压器
- javascript - 发送 res.status.send() 后 Firebase 调用仍在执行
- java - 来自Android中不同类的setContentView(R.layout.xy)
- javascript - JavaScript `debugger` 关键字是如何工作的?
- bash - 在文本文件的第一行之前插入文件名 - 文件扩展名
- java - 如何在 Spring Boot 中使用 @ManyToMany 正确保存实体?
- javascript - 为什么我在一个简单的 for 循环后又增加了一次?
- c# - 在 SQL Server 上运行完整的 EF 查询
- ruby-on-rails - 是否可以使用片段缓存指定缓存或确定特定调用的缓存命中/未命中率
- javascript - 添加到 Promise 的成功和拒绝处理程序不会激活