Fix "having" clauses

This pull request follows from the following question on the forum:

http://collabtive.o-dyn.de/forum/viewtopic.php?f=11&t=13178&sid=2d54503049b4dd323fc7751c7f51f8a6

Looking at SQL manuals, the "HAVING" clause can only be used when it performs aggregate functionality — That is, when it is used together with eg. "GROUP BY". Some pointers to this:

http://www.sql-tutorial.net/SQL-HAVING.asp
https://en.wikipedia.org/wiki/Having_%28SQL%29
http://www.techonthenet.com/sql/having.php

I see Microsoft SQL Server allows using HAVING without GROUP BY:

http://technet.microsoft.com/en-us/library/ms173260%28v=SQL.110%29.aspx

Quoting one of the Stackoverflow answers at https://stackoverflow.com/questions/9253244/sql-having-vs-where

WHERE clause introduces a condition on individual rows; HAVING clause introduces a condition on aggregations, i.e. results of selection where a single result, such as count, average, min, max, or sum, has been produced from multiple rows.