MySQL Select 计数,按不同分组 - 两列

MySQL Select count, group by distinct - two columns

我想上车 Mysql :

所以我想知道每个跑步者所在的行数,即使他在 runnerA 或 runnerB 中。

一个例子:

我的数据:

id id_runnerA id_runnerB done
1 12 5 1
2 20 12 1
3 12 1 3

结果应该是:

id_runner count
12 2
20 1
5 1

谢谢

看起来可能是

SELECT
  id_runner, count(*)
FROM
  (
    SELECT id_runnera as id_runner FROM t WHERE done < 2
    UNION ALL
    SELECT id_runnerb FROM t WHERE done < 2
  ) x
GROUP BY
  id_runner

但如果能看到更多的测试数据会很有帮助