计数按UNION ALL的值分组

时间:2015-02-07 13:24:22

标签: mysql

我在mySQL中有以下查询

`SELECT * FROM (select assoc1 from fab_cbd where tournament = 65   
union all    
select assoc2 from fab_cbd where tournament = 65) x`

使用这个,我得到包含这两列值的完整列表。我想要做的是按这些值进行分组并计算出现次数。

提前致谢。

1 个答案:

答案 0 :(得分:1)

然后添加group by

SELECT assoc, count(*)
FROM (select assoc1 as assoc from fab_cbd where tournament = 65   
      union all    
      select assoc2 from fab_cbd where tournament = 65
     ) x
GROUP BY assoc;