To convert rows to columns in Oracle SQL, you can use the PIVOT operator. Here’s an example:
SQL PIVOT Operator
Let’s say you have a table named “sales” with the following data:
And you want to convert the rows into columns, with each product as a separate column and the months as the rows. You can achieve this using the PIVOT operator as follows:
This query will produce the following output:
In this output, each row represents a month, and each column represents a product. The values in each cell represent the revenue for that product in that month.
Related