I have a table with a large number of columns (around 900 columns, which makes it unfeasible to individually write all the column names). How can I dynamically unpivot only the columns with the suffix '_next' & '_last' (there are hundreds of such columns)? For example:
TABLE:
+---------+------------+-----------+-------+----------+-----------+
|name |product_next|upload_last|product|books |active_next|
+---------+------------+-----------+-------+----------+-----------+
| alice| a | 100 |apple | 10 | 1 |
| bob| b | 23 |orange | 2 | 0 |
+---------+------------+-----------+-------+----------+-----------+
FINAL TABLE (after unpivoting):
+---------+------------+-----------+-------+----------+
|name |metric |value |product|books |
+---------+------------+-----------+-------+----------+
| alice|product | a |apple | 10 |
| bob|product | b |orange | 2 |
| alice|upload | 100 |apple | 10 |
| bob|upload | 23 |orange | 2 |
| alice|active | 1 |apple | 10 |
| bob|active | 0 |orange | 2 |
+---------+------------+-----------+-------+----------+