sql >> Base de Datos >  >> RDS >> Mysql

Filtrar una tabla unida

select 
    case when e.published and a.type not in('large','medium') then 'Met condition' else 'Not met condition' end conditions
    , count(distinct e.id) totals
    , group_concat(distinct e.id) event_ids
    , count(distinct e.id) * 100.0 / x.total_cnt percentage
from events e
join Attributes a on a.event_id = e.id
cross join (select count(*) as total_cnt from events) x
group by case when e.published and a.type not in('large','medium') then 'Met condition' else 'Not met condition' end, total_cnt

db<>fiddle aquí