pseudo sql to sql