Fixed bug in count clause with new join style.
Added missing group by and having in count clause.
Fixed count queries with group and having clauses.