Query extended by having clauses

Signed-off-by: Kristián Feldsam <feldsam@gmail.com>