出处:kelvin19840813 的博客 http://www.cnblogs.com/kelvin19840813/
您的支持是对博主最大的鼓励,感谢您的认真阅读。本文版权归作者所有,欢迎转载,但请保留该声明。
发现decode行转列之后 , 小数, 负数都会自动抹去 , 需要to_char加工一下 , 并没有找到相关文献解释为什么抹去
SQL> create table test0724 (name varchar(20),month number(2),num NUMBER(6,2));
insert into test0724 values(‘a‘,01,1.1);
insert into test0724 values(‘a‘,01,2.2);
insert into test0724 values(‘b‘,02,1.1);
insert into test0724 values(‘b‘,02,2.2);
insert into test0724 values(‘a‘,02,1.1);
insert into test0724 values(‘a‘,02,2.2);
insert into test0724 values(‘b‘,01,1.1);
insert into test0724 values(‘b‘,01,2.2);
insert into test0724 values(‘a‘,03,-1.1);
insert into test0724 values(‘a‘,03,-2.2);
insert into test0724 values(‘b‘,03,-1.1);
insert into test0724 values(‘b‘,03,-2.2);
select name,min(jan),min(feb),min(mar) from (
select name,decode(month,01,to_char(num,‘S99999.99‘),0) jan,decode(month,02,to_char(num,‘S99999.99‘),0) feb,decode(month,03,to_char(num,‘S99999.99‘),0) mar from test0724 ) group by name;