刚才在数据库试了这个,报错:不是单分组函数
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
查询语句:select fno,max(decode(category,'l1',value)) l1,max(decode(category,'l2',value)) l2,max(decode(category,'l3',value)) l3,max(decode(category,'l4',value)) l4,max(decode(category,'l5',value)) l5,max(decode(category,'l6',value)) l6 from table

解决方案 »

  1.   

    最后面,你加一个 group by fno
      

  2.   

    嗯,下面一个测试的加group by fno查询成功了,但是上面那个加了还是报错未找到要求的From关键字,这一般会是什么情况呢
      

  3.   

    如果把sql格式化之后再发帖子感觉会更好点!
      

  4.   

    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
      

  5.   

    我试过了在第一个语句里面加上group by fno 也可以执行,你仔细检查一下标点、括号,是不是有错漏的地方