Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Contagem de mesclagem do MySQL várias colunas


Você pode usar union all para desdinamizar seu conjunto de dados e, em seguida, agregar:
select disease, count(*) total
from (
    select disease from mytable
    union all select additional_disease1 from mytable
    union all select additional_disease2 from mytable
    union all select additional_disease3 from mytable
    union all select additional_disease4 from mytable
) t
group by disease
order by total desc, disease