Problems / Bool Flags to Categories / Editorial
CASE
CASE WHEN is_mobile THEN 'mobile' WHEN is_desktop THEN 'desktop' WHEN is_tablet THEN 'tablet' END
= TRUE
GROUP BY
COUNT(*)
device_type
One-hot flag columns are a *wide* (pivoted) encoding of a categorical value, common in ML feature exports and survey data. Collapsing them back — sometimes called reverse pivoting or unpivoting — is just a CASE ladder, after which ordinary GROUP BY analytics work again. The one thing to verify before trusting the ladder is the one-hot invariant itself: if two flags could both be true, the first matching WHEN silently wins, and if none could be true, you'd need an ELSE bucket. Checking is_mobile + is_desktop + is_tablet = 1 per row is a cheap data-quality assertion when the invariant matters.
is_mobile + is_desktop + is_tablet = 1
Solve Bool Flags to Categories yourself →