Bitwise Interview Question

Had to write complex SQL queries. And told to optimize the code I wrote in C in the second round.