2016-08-31 144 views

回答

2

一個簡單的聯盟會給你一套所有的舞者:

select DISTINCT dancer1 as dancer from table 
union 
select DISTINCT dancer2 as dancer from table 

如果你想計數:

select count(all_dancers.dancer) from ( 
    select DISTINCT dancer1 as dancer from table 
    union 
    select DISTINCT dancer2 as dancer from table 
) all_dancers 
+0

是工會需要? –

+0

@safinchacko我不認爲一個獨特的可能在同一時間在多個列上。我剛剛在MySQL – sisanared

+0

中試過它只有在UNION計數是正確的,謝謝@shravster! – puls8

0

嘗試此查詢

select count(distinct dancer1,dancer2 ) from table 
0
SELECT COUNT(DISTINCT dancer) 
    FROM 
    (SELECT dancer1 dancer 
     FROM my_table 
     UNION 
     SELECT dancer2 
     FROM my_table 
    ) x;