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
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
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
是可以实现的,关键我对Case用法不熟!
(case when b=2 then c else 0 end) c2,
(case when b=3 then c else 0 end) c3
from tablename
(case b when 2 then c else 0 end) as c2,
(case b when 3 then c else 0 end) as c3
from tablename
(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