这个完全用sql语句无法解决,需要自己写一些代码来实现。

解决方案 »

  1.   

    注意B是己知的
    是可以实现的,关键我对Case用法不熟!
      

  2.   

    select A,B,(case when b=1 then c else 0 end) c1,
           (case when b=2 then c else 0 end) c2,
           (case when b=3 then c else 0 end) c3
    from tablename
      

  3.   

    select  A,B,(case b when  1  then  c  else  0  end) as c1,
                    (case b when  2  then  c  else  0  end) as c2,
                    (case b when  3  then  c  else  0  end) as c3
      from  tablename
      

  4.   

    select A,B,(case b when 1 then c else 0 end) as c1,
     (case  b  when    2    then    c    else    0    end)  as  c2,
     (case  b  when    3    then    c    else    0    end)  as  c3,
     (case  b  when    4    then    c    else    0    end)  as  c4
          from    tablename