Mysql
 sql >> Database >  >> RDS >> Mysql

Mysql merge contare più colonne

Puoi usare union all per annullare il pivot del set di dati e quindi aggregare:

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