Fix planning issue when using DISTICT aggregations in HAVING clause

Planning fails with a "Multiple entries with same key" error
Add test for HAVING with DISTINCT aggregations