Convert where condition to sql