有一个人员表
id    name   xh
1      张三     1
2      李四     2
3      王五     3
………………
希望能用sql取成一条记录,每个人员相当于是一个字段取出,不是在一个字段里面。
select ……………… from ………………
张三     李四     王五

解决方案 »

  1.   

    select case when id=1 then name end,
           case when id=2 then name end,
           case when id=3 then name end
    from table;
      

  2.   

    查询语句中 PIVOT 子 句 和 UNPIVOT 子 句
      

  3.   

    oracle 11后,有个pivot方法
    with t as 
    (select 1 id , '张三' name from dual 
    union all 
    select 2 id ,'李四' name from dual
    union all
    select 3 ,'王五' from dual
    union all 
    select 4, '赵四' from dual)select *  from  (select id,name from t ) pivot(max(name) for id in (1,2,3,4))
      

  4.   


    如果有一个分组列名为codeid,这种pivot语句是怎么个写法学习下