AnalystPath

Combined Device Feature Flags

SQLMediumMid level~15 min

Problem

Each device stores its enabled features as a bitmask integer in device_flags(device_id, flag_mask), where each bit represents one feature. Compute two aggregate values across all devices: shared_flags, the features enabled on every device (the bitwise AND of all flag_mask values), and union_flags, the features enabled on at least one device (the bitwise OR of all flag_mask values). Return a single row with both values.

Tables

Example rows — the live problem includes the full dataset.

device_flags
device_idflag_mask
15
212
37

Expected output

Your answer should return 1 row with the columns shared_flags, union_flags.

Starter code (SQL)

SELECT *
FROM device_flags;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions