我有两个查询(返回正确的结果),我基本上想组合计数然后分组:
Select profileID,
Count(*) as numTotal from replies
GROUP BY profileID;
结果:
profileID: 1,2,3
numTotal: 10,1,1
和
Select postedByID,
Count(*) as numTotal from WIRL_01.posts
Group by postedByID
结果:
postedByID: 1,2,3
numTotal: 13,4,3
在这种情况下,我想将 profileID = postedByID 分组。我尝试了以下但无济于事:
Select profileID,
Count(*) as numTotal
from replies
INNER JOIN posts ON replies.profileID = posts.postedByID
Group by profileID
结果:
postedByID: 1,2,3
numTotal: 130,4,3
任何指导将不胜感激。
编辑:
这个查询让我更接近一点,但是如何按 profileID 对结果进行分组?
Select profileID, Count(*) from WIRL_01.replies Group by profileID
UNION ALL
Select postedByID, Count(*) from WIRL_01.posts Group by postedByID
给我...
profileID:1,2,3,1,2,3 计数(*):10,1,1,13,4,3
我需要的是:
profileID: 1,2,3 计数(*):23,5,4