且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL添加联接给出不正确的结果

更新时间:2022-02-21 21:58:28

另一种可能的解决方案:

Another possible solution:

select
  a.userId,
  sum(a.postStatus = 0) published,
  sum(a.postStatus = 1) inactive,
  sum(a.postStatus = 5) recalled,
  sum(a.postStatus = 6) deleted,
  b.unChecked
from userData a left outer join 
    (select userId, sum(poststatus = 10) unChecked
    from userDataMod
    group by userId)
  b on a.userId = b.userId 
 where a.userId = 1;