Query to display output horizontally

后端 未结 3 1759
野性不改
野性不改 2021-01-19 15:10

I need to display a query output in a horizontal manner. I have some example data

create table TestTable (id number, name varchar2(10))

insert into TestTabl         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 15:28

    To pivot, you should use the pivot clause of the select statement:

    select *
      from testtable
     pivot ( max(name)
             for id in (1,2,3,4)
           )
    

    This is not particularly pretty to do in SQL, so you should consider carefully whether this is what you want to do. I normally use Oracle Base for pivoting examples but there are many out there.

    Here's a little SQL Fiddle to demonstrate.

提交回复
热议问题