informix 求行的最值

theone5288 2010-07-09 11:20:29
原表T
a b c d e
1 2 4 5 9
1 2 8 4 5
3 3 2 5 6

想求出每一行的最值,即
a b c d e max
1 2 4 5 9 9
1 2 8 4 5 8
3 3 2 5 6 6

哪位大侠给出出招啊,我想到的方法
1:行列转置,然后用max函数求,再转置回去
2:用perl,将表数据导出给数组,取出每行的最值,再入会库中
大侠们给解决下吧
...全文
140 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
theone5288 2010-08-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 minitoy 的回复:]

SQL code
SQL> select * from t;

A B C D E MAX
--------------------- -----------……
[/Quote]
恩,你这个可以,但是要是字段很多的话,会不会效率低些呢?
minitoy 2010-07-28
  • 打赏
  • 举报
回复
SQL> select * from t;

A B C D E MAX
--------------------- --------------------- --------------------- --------------------- --------------------- ---------------------
1 12 3 2 12
3 23 5 3 6
32 64 6 8 32
23 66 87 34 23

SQL>
SQL> update T
2 set t.max=t.a;

4 rows updated
SQL> update t
2 set t.max=decode(sign(t.max-b),1,t.max,b);

4 rows updated
SQL> update t
2 set t.max=decode(sign(t.max-c),1,t.max,c);

4 rows updated
SQL> update t
2 set t.max=decode(sign(t.max-d),1,t.max,d);

4 rows updated
SQL> update t
2 set t.max=decode(sign(t.max-e),1,t.max,e);

4 rows updated
SQL> SELECT * FROM t;

A B C D E MAX
--------------------- --------------------- --------------------- --------------------- --------------------- ---------------------
1 12 3 2 12 12
3 23 5 3 6 23
32 64 6 8 32 64
23 66 87 34 23 87

SQL>
minitoy 2010-07-28
  • 打赏
  • 举报
回复
update T
set t.max=t.a;
update t
set t.max=decode(max>b,max,b);
update t
set t.max=decode(max>c,max,c);
update t
set t.max=decode(max>d,max,d);
update t
set t.max=decode(max>e,max,e);
theone5288 2010-07-27
  • 打赏
  • 举报
回复
我写了个perl将数据取出,算出每行的最值,在入回表里了!!
小灰狼W 2010-07-09
  • 打赏
  • 举报
回复
select t.*,greatest(a,b,c,d,e) maxval
from t
theone5288 2010-07-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wildwave 的回复:]
select t.*,greatest(a,b,c,d,e) maxval
from t
[/Quote]
这个greatest是什么东西?我在informix里执行报错误啊,
Routine (greatest) can not be resolved
你的能执行?

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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