oldwain随便写 http://oldwain.itpub.net/
<a href="http://oldwain.itpub.net">oldwain随便写</a>
itpub论坛回复: 分组求积
上一篇 /
下一篇 2005-10-10 00:00:00
/ 个人分类:Oracle
问题:
wenzai169:
从未遇到的SQL问题?
一表A结构大致如下ITPUB个人空间{9NB(~ gv4KD
ID QTY
J7\%~7@ lc01 2
w%n$Gl+Vfg9^-p02 4ITPUB个人空间"|"M$h*EoU a
H
3 6
y?&`5Cjy04 5
u)x;Nv.eh[.m;g,^0要求能够得到QTY字段的乘积2*4*6*5,
我的回答:
ITPUB个人空间Sc"X]*\ C9{9u ?Y运用一下数学知识, 可以这样简化:
4K
o!t ].i5z8N0ITPUB个人空间pb%g*lS
a * b * c = power(10, log(10, a) + log(10, b) + log(10, c)ITPUB个人空间5|9N8B x7uuT;@!Q8~
ITPUB个人空间8z1D9}P
b/C"V
这样, 楼主的问题可以用这样的单条sql来解决:
{Dv9bl2P)R#C4q0ITPUB个人空间_"I1{*Y `9d"Ux
Select power(10, Sum(Log(10, qty))) From t
scott@O9I.US.ORACLE.COM> drop table t;
Table dropped.
scott@O9I.US.ORACLE.COM> create table t (id number, qty number);
Table created.
scott@O9I.US.ORACLE.COM> insert into t values(1, 2);
1 row created.
scott@O9I.US.ORACLE.COM> insert into t values(2, 4);
1 row created.
scott@O9I.US.ORACLE.COM> insert into t values(3, 6);
1 row created.
scott@O9I.US.ORACLE.COM> insert into t values(4, 5);
1 row created.
scott@O9I.US.ORACLE.COM> commit;
Commit complete.
scott@O9I.US.ORACLE.COM> Select power(10, Sum(Log(10, qty))) From t ;
POWER(10,SUM(LOG(10,QTY)))
M9P!Lv$J5aeF%u6o&?#A0--------------------------
"cp4O9CbQo-`\0240
scott@O9I.US.ORACLE.COM>
虽然举的例子没有用到分组功能, 不过加上group by,同样的方法依然可用。
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG: