我有三个函数调用,其中我需要一列中的所有记录。我一直无法做到这一点,并希望推动正确的方向。我正在使用db2数据库。
函数调用:
schema1.Usage ('element', 20140101, 20140714)
schema1.TOTAL_Usage ('element', 20140101, 20140714)
schema1.Usage ('element', 20140101, 20140714)/schema1.TOTAL_Usage ('element', 20140101, 20140714)
以下是我尝试过但没有成功的事情:
select * from
(VALUES schema1.Usage ('element', 20140101, 20140714)
,schema1.TOTAL_Usage ('element', 20140101, 20140714)
,schema1.Usage ('element', 20140101, 20140714)/schema1.TOTAL_Usage ('element', 20140101, 20140714) AS X(a);
答案 0 :(得分:1)
如果这些是标量函数,只需将它们放在select
:
select schema1.Usage('element', 20140101, 20140714),
schema1.TOTAL_Usage('element', 20140101, 20140714)
schema1.CAPABILITY_Usage('element', 20140101, 20140714)/schema1.TOTAL_Usage('element', 20140101, 20140714) AS X(a)
from sysibm.sysdummy1;
答案 1 :(得分:0)
基于http://oscarvalles.wordpress.com/2013/03/29/select-without-table-in-db2/
假设这有效:
Values schema1.Usage('element', 20140101, 20140714)
但是如果你想要所有的值,你可以将它们连接成一个字符串......但不能多个引用的列
然后可能......Values schema1.Usage('element', 20140101, 20140714) & ' ' &
schema1.TOTAL_Usage('element', 20140101, 20140714) & ' ' &
schema1.CAPABILITY_Usage('element', 20140101, 20140714)/schema1.TOTAL_Usage ('element', 20140101, 20140714)
戈登发布的内容......如引用的那样 http://www.dbforums.com/db2/975637-dual-table-db2-udb.html
答案 2 :(得分:0)
只需进行一些小调整,您的查询就可以了,我假设X是1行,3列,而不是相反
select * from (
VALUES ( schema1.Usage ('element', 20140101, 20140714)
, schema1.TOTAL_Usage ('element', 20140101, 20140714)
, schema1.Usage ('element', 20140101, 20140714)
/ schema1.TOTAL_Usage ('element', 20140101, 20140714)
)
) AS X(a,b,c);
将分部移到外部选择可能会更好:
select a, b, a/b from (
VALUES ( schema1.Usage ('element', 20140101, 20140714)
, schema1.TOTAL_Usage ('element', 20140101, 20140714) )
) AS X(a,b);