开发者

Multiple COUNT in 1 SQLITE Query

开发者 https://www.devze.com 2023-01-21 07:41 出处:网络
Using SQLite. SELECT c.*, COUNT(m.course_id) AS \"meeting_count\", COUNT(r.meeting_id) AS \"race_co开发者_JAVA技巧unt\"

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消