TEIID-2983, TEIID-2984: Fixing the error with COUNT(columnName) by rewri...

...ting the query