SQL SUM and COUNT returning wrong values
问题 I found a bunch of similar questions but nothing worked for me, or I am too stupid to get how to do it right. The visit count works fine if I use COUNT(DISTINCT visits.id) but then the vote count goes totally wrong - it displays a value 3 to 4 times larger than it should be. So this is the query SELECT SUM(votes.rating), COUNT(visits.id) FROM topics LEFT JOIN visits ON ( visits.content_id = topics.id ) LEFT JOIN votes ON ( votes.content_id = topics.id ) WHERE topics.id='1' GROUP BY topics.id