我现在有2张表test01编号  状态  
 1     新增
 2     撤销
 3     故障
 4     新增 用一个 sql语句 出现的 情况 是 
编号    新增      撤销     故障 
 1        1        null    null
 2        null     1       null 
 3        null     null      1
 4        1        null      null我 在线等待 ,谢谢 

解决方案 »

  1.   

    我现在有1张表test01编号  状态  
     1     新增
     2     撤销
     3     故障
     4     新增 用一个 sql语句 出现的 情况 是 
    编号    新增      撤销     故障 
     1        1        null    null
     2        null     1       null 
     3        null     null      1
     4        1        null      null我 在线等待 ,谢谢
      

  2.   

    select 
    编号,
    decode(状态,'新增',1,null) 新增,
    decode(状态,'撤销',1,null) 撤销,
    decode(状态,'故障',1,null) 故障
    from test01
      

  3.   

    select 
    编号,
    decode(状态,'新增',1,'') ,
    decode(状态,'撤销',1,'') ,
    decode(状态,'故障',1,'') 
    from test01
      

  4.   

    用decode 和 case when 都可以。
    select 
    编号 "编号",
    (case when 状态 = '新增' then 1 else null end) "新增",
    (case when 状态 = '撤销' then 1 else null end) "撤销",
    (case when 状态 = '故障' then 1 else null end) "故障",
    from test01