Infymax interview question

Basic logical program and mysql query