Bitwise Interview Question

SQL queries and Java pattern