报错:未找到要求的From关键字

zdczdccccc 2014-07-16 09:17:53
数据库结构是需要用到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


...全文
2688 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zdczdccccc 2014-07-17
  • 打赏
  • 举报
回复
引用 7 楼 zlloct 的回复:
跟你的别名有关系,像这种别名:8.年代码 最好是别加特殊字符
正解
iceCache 2014-07-16
  • 打赏
  • 举报
回复
如果把sql格式化之后再发帖子感觉会更好点!
zdczdccccc 2014-07-16
  • 打赏
  • 举报
回复
引用 2 楼 wmxcn2000 的回复:
最后面,你加一个 group by fno
嗯,下面一个测试的加group by fno查询成功了,但是上面那个加了还是报错未找到要求的From关键字,这一般会是什么情况呢
卖水果的net 2014-07-16
  • 打赏
  • 举报
回复
最后面,你加一个 group by fno
zdczdccccc 2014-07-16
  • 打赏
  • 举报
回复
刚才在数据库试了这个,报错:不是单分组函数 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
善若止水 2014-07-16
  • 打赏
  • 举报
回复
很经典的行列转换,楼主最好把问题的原因弄明白。
ghx287524027 2014-07-16
  • 打赏
  • 举报
回复
我试过了在第一个语句里面加上group by fno 也可以执行,你仔细检查一下标点、括号,是不是有错漏的地方
CT_LXL 2014-07-16
  • 打赏
  • 举报
回复
引用 6 楼 zdczdcc 的回复:
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
跟你的别名有关系,像这种别名:8.年代码 最好是别加特殊字符
zdczdccccc 2014-07-16
  • 打赏
  • 举报
回复
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
zdczdccccc 2014-07-16
  • 打赏
  • 举报
回复
引用 4 楼 mensuo1111 的回复:
如果把sql格式化之后再发帖子感觉会更好点!
嗯嗯,谢谢你的提醒

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧