Query Error: Reference 'GM' not supported (reference to group function)