数据库结构是需要用到decode转换的那种。
第一列fno,第二列是category。一个fno对应不同的category,但是每个fno对应的category数又不固定。
类似:
fno category id(表示:category的值)
1 类1 x1
1 类2 y2
1 类3 z3
2 类3 x4
2 类4 y5
2 类5 z6
2 类6 x7
3 类2 x8
3 类6 x9
请问该怎么转换成这种
fno 类1 类2 类3 类4 类5 类6
1 x1 y2 z3
2 x4 y5 z6 x7
3 x8 x9
我用MAX(DECODE())函数报错:未找到要求的from关键字
这是语句:
select fno,max(decode(category,'班组',id,'')) 班组,max(decode(category,'版本',id,'')) 版本,max(decode(category,' 1.OCV',id,'')) OCV,max(decode(category,' 11.版本号',id,'')) 版本号,max(decode(category,'产线',id,'')) 产线,max(decode(category,'日期',id,'')) 日期,max(decode(category,' 3.インピーダンス',id,'')) インピーダンス,max(decode(category,' 8.年代码',id,'')) 8.年代码,max(decode(category,'星期',id,''))星期,max(decode(category,' 12.班组代号',id,'')) 12.班组代号,max(decode(category,' 2.CCV',id,'')) CCV,max(decode(category,' 4.インピーダンス差',id,'')) インピーダンス差,max(decode(category,'上传时间',id,'')) 上传时间,max(decode(category,' 13.serial No.',id,'')) serial No,max(decode(category,' 6.机种代码',id,'')) 机种代码,max(decode(category,' 9.月代码',id,'')) 月代码,max(decode(category,' 10.日期',id,'')) 日期,max(decode(category,' 5.OCV',id,'')) OCV,max(decode(category,' 7.仕向地',id,'')) 仕向地,max(decode(category,'机种',id,'')) 机种,max(decode(category,'仕向',id,'')) 仕向,max(decode(category,'周次',id,'')) 周次 from table1
------解决方案--------------------
最后面,你加一个 group by fno
------解决方案--------------------