rewrite SQL-Query