使用左连接时列名称错误无效

时间:2014-12-10 06:29:11

标签: sql

我在执行以下查询时收到无效的列名' PostId' 错误

 Select a.SuburbDiscussionID,SUM((CASE WHEN b.postcnt IS NULL THEN 0 ELSE b.postcnt END)  + (CASE WHEN c.replycnt IS NULL THEN 0 ELSE c.replycnt END)) AS TotCount
    from SuburbDiscussions a
    left join (SELECT COUNT(*) as postcnt,Posts.DiscussionId FROM Posts
    GROUP BY Posts.DiscussionId) b on a.DiscussionId = b.DiscussionId
    left join (SELECT COUNT(*) as replycnt,PostComments.PostId FROM PostComments
    GROUP BY PostComments.PostId) c on b.PostId = c.PostId
    where a.IsDelete = 0 and a.UserID != 33
    Group by a.SuburbDiscussionID
    ORDER BY TotCount

为什么在我的查询中未检测到 PostId 列?

0 个答案:

没有答案