X Interview Question

Including SQL and programming problem.