Вы можете использовать union all
и некоторые case
logi c:
select customerid,
(case when max(is_online) = 1 and max(is_instore) = 1 then 'both'
when max(is_online) = 1 then 'online'
else 'instore'
end) as grouping
from ((select customerid, 1 as is_online, 0 as is_instore
from a
) union all
(select customerid, 0 as is_online, 1 as is_instore
from b
)
) ab
group by customerid;