student表中数据:name type
--------------------------
大黄  3
小白  1
多多  1
大黄  1
大黄  2
小宝  1
小宝  2
小宝  3查询结果:type=1 type=2 type=3
------------------------
小白    null   null
多多    null   null
大黄    大黄   大黄
小宝    小宝   小宝

解决方案 »

  1.   

    select max(case when type=1 then name end) t1,
        max(case when type=2 then name end) t2,
        max(case when type=3 then name end) t3
    from student
    group by name
      

  2.   

    建议用decodeselect t.name, 
    max(decode(t.type,'1',t.type,null)) type1,
    max(decode(t.type,'2',t.type,null)) type2,
    max(decode(t.type,'3',t.type,null)) type3
    from student t
    group by t.name
      

  3.   

    晕,看错了。下面这个select 
    max(decode(t.type,'1',t.name,null)) type1,
    max(decode(t.type,'2',t.name,null)) type2,
    max(decode(t.type,'3',t.name,null)) type3
    from test t
    group by t.name
      

  4.   

     select max(decode(type,1,type,null)) type1,
                  max(decode(type,2,type,null)) type2,
      max(decode(type,3,type,null)) type3
      from s_stu
      

  5.   

    看了下decode函数,很好用,那要是判断的值为“type<>1”怎么处理好呢,这个函数还好用吗?
      

  6.   

    看了下decode函数,如何处理“type<>1”还可以用这个函数吗?
      

  7.   

    看了下decode这个函数,如果处理type<>1还可以使用这个函数吗?