此查詢不選擇,無評論或無表決數據,我如何解決?3個表的mysql查詢
SELECT
blog_posts.*,
COUNT(DISTINCT(blog_comments.CommentID)) AS CountComments,
COUNT(DISTINCT(blog_votes.VoteID)) AS CountVotes,
AVG(DISTINCT(blog_votes.Vote)) AS AvgVote
FROM blog_posts
INNER JOIN blog_comments ON blog_comments.CommentBlogID=blog_posts.BlogID
INNER JOIN blog_votes ON blog_votes.VoteBlogID=blog_posts.BlogID
ORDER BY blog_posts.BlogID
LIMIT 0,10
'GROUP BY blog_post.col1,blog_posts.col_2,...' – lad2025
所以你想計數評論,投票和平均投票數據? –
@MichaelAntonio它的真實 –