我正在尝试从表中计算子记录的总数但似乎不起作用。在左连接时,计数而不是父表中的记录总数而不是子表。
SELECT Count(comment) as total
FROM dbo.photo_comment LEFT JOIN users_pics ON photo_comment.resp_email = users_pics.email
WHERE photo_comment.wardrobe = MMColParam
photo_comment是父表,users_pics是子表。我想要查询的是计算图片上的评论总数
答案 0 :(得分:1)
您需要按照图片进行分组。我假设它是这样的,基于识别图片的字段的名称:
SELECT COUNT(comment) ,
user_pics.picture
FROM dbo.photo_comment
LEFT JOIN users_pics ON photo_comment.resp_email = users_pics.email
WHERE photo_comment.wardrobe = MMColParam
GROUP BY picture