Each GROUP BY expression must contain at least one column that is not an outer reference
To start with you can’t do this: The HAVING clause can only contain things which are attributes of the aggregate groups. In addition, 1, 2, 3 is not valid in GROUP BY in SQL Server – I think that’s only valid in ORDER BY. Can you explain why this isn’t what you are looking for: