Multiple COUNT in 1 SQLITE Query
Using SQLite.
SELECT c.*,
COUNT(m.course_id) AS "meeting_count",
COUNT(r.meeting_id) AS "race_co开发者_JAVA技巧unt"
FROM course c
LEFT JOIN meeting m ON m.course_id = c.id
LEFT JOIN race r ON r.meeting_id = m.id
GROUP BY c.id
Course has meetings has races.
Trying to select the correct count for course meetings and course races. The problem is the above query is returning the same count for "meeting_count" as "race_count". What am I doing wrong?
try adding DISTINCT like COUNT(DISTINCT m.course_id)
精彩评论