Dette er grundlæggende en pivot-forespørgsel. Jeg ville gøre det med betinget aggregering:
select user, access_date,
max(case when FORMFACTOR = 'Mobile' then 1 else 0 end) as KEY_MOBILE,
max(case when FORMFACTOR = 'Desktop' then 1 else 0 end) as KEY_DESKTOP,
(case when max(case when FORMFACTOR = 'Mobile' then 1 else 0 end) > 0 and
max(case when FORMFACTOR = 'Desktop' then 1 else 0 end) > 0
then 1 else 0
end) as KEY_MOBILE_DESKTOP
from table t
group by user, access_date;