generate sql, add condition