I'm having some issues pivoting a table. I found some examples here on SO but they all had fixed "pivoting column names" and they all aggregated the values, which doesn't work for me.
I have the following query:
SELECT
CNAME,
CDATE,
CVOLUME
FROM
VOLUMES
WHERE
to_char(CDATE, 'MM') = '11'
ORDER BY
CNAME ASC
Which returns the following table (Table 1):
CNAME | CDATE | CVOLUME |
---|---|---|
Company A | 2021-11-30 | 320 |
Company A | 2021-11-29 | 347 |
Company A | ... | ... |
Company A | 2021-11-01 | 298 |
Company B | 2021-11-30 | 76 |
Company B | 2021-11-29 | 82 |
Company B | ... | ... |
Company B | 2021-11-01 | 68 |
For interoperability with another software, I have to create a report where the dates become columns and the volume goes into its respective dates. Like this (Table 2):
CNAME | 2021-11-30 | 2021-11-29 | ... | 2021-11-01 |
---|---|---|---|---|
Company A | 320 | 347 | ... | 298 |
Company B | 76 | 82 | ... | 68 |
There's no aggregation of data (the volumes are still all the same) and the new column names are "dynamically" created based on the date. Can someone help me out on how to convert from Table 1 to Table 2? I'm using Oracle 12c.
Thanks in advance.