2015-02-07 16 views
0

我有以下查詢中的MySQL計數從UNION的值分組的所有

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

使用此我得到的名單與這兩列的值。我想要做的是按這些值進行分組並計算出現次數。

在此先感謝。

回答

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; 
+0

謝謝你的查詢。 – dimoss 2015-02-07 13:48:06