You can do this by generating all possible combinations using cross join
, and the using left join
to bring in the original data. The rest is just aggregation:
select a.aliasname, count(d.aliasname) as quest_count, ic.is_correct
from (select distinct aliasname from tbl_demo
) a cross join
(select distinct is_correct from tbl_demo
) ic left outer join
tbl_demo d
on d.aliasname = a.aliasname and d.is_correct = ic.is_correct
group by a.aliasname, ic.is_correct;