Postgres Check If Column Exists In Dataframe Group By Mean