In Oracle, there are different ways to make multiple lines horizontal. One way is to use the PIVOT function, which rotates rows into columns. Here's a procedure using the PIVOT function:
For example, suppose you have a table named "sales" with columns "region," "product," and "sales_amount." To pivot the data and make the regions horizontal, you can use the following query:
SELECT * FROM ( SELECT region, product, salesamount FROM sales ) PIVOT ( SUM(salesamount) FOR region IN ('North' AS "North", 'South' AS "South", 'East' AS "East", 'West' AS "West") ) ORDER BY product;
This query selects the columns needed for the result set, pivots the rows to columns using the PIVOT function, and aliases the resulting columns with the corresponding region name. Finally, the result set is sorted by product.
Asked: 2022-09-01 11:00:00 +0000
Seen: 9 times
Last updated: Nov 28 '22