add having clause to query