Is there a way in athena/presto to get column names based on a condition and use it in group by?
SHOW COLUMNS FROM {table_name}
This query gives me the column details. But I want to use only the column names in some other query. The structure of the table looks like
name_of_service | cost | usage_date | user_123 | user_212 | user_342 | user_5832 | ...
And so on. There are around 500 columns
The use case I am looking at, looks somewhat like this -
SELECT SUM(cost), {column_names_which_start_with_user}
FROM {db}
GROUP BY cost, {column_names_which_start_with_user}
I am not in control of populating the db and there are 100s of columns whose names change every month. Is there a way to do this?