Infymax Interview Question

Basic logical program and mysql query