[英]Oracle Apex Sum of 2 interactive grid columns in third grid
I have 3 Interactive grids in my Apex application.我的 Apex 应用程序中有 3 个交互式网格。 The source table for all the three is same, just that the flags are different.
这三个的源表是相同的,只是标志不同。
First grid:第一个网格:
select kpi_a_pk, dept_name, to_char(kpi_a_1,'999,999,999,999'),to_char(kpi_a_2,'999,999,999,999'),to_char(kpi_a_3,'999,999,999,999')
FROM KPI where dept_name = 'A'
Columns are numeric but need to be rendered comma separated.列是数字,但需要以逗号分隔。 In processes i am converting them using to_number to save them.
在流程中,我正在使用 to_number 转换它们以保存它们。
Second grid:第二格:
select kpi_a_pk, dept_name, to_char(kpi_a_1,'999,999,999,999'),to_char(kpi_a_2,'999,999,999,999'),to_char(kpi_a_3,'999,999,999,999')
from KPI where dept_name = 'B'
Third grid needs to be sum of the columns A and B:第三个网格需要是 A 列和 B 列的总和:
select kpi_a_pk, dept_name, to_char(kpi_a_1,'999,999,999,999'),to_char(kpi_a_2,'999,999,999,999'),to_char(kpi_a_3,'999,999,999,999')
from KPI where dept_name = 'C'
So its expected query would have the logic like:所以它的预期查询将具有如下逻辑:
KPI_A_1 = case when dept_name = 'A' then kpi_a_1
+case when dept_name = 'B' then kpi_a_1
But when i try writing something like this in query, it returns nothing.但是当我尝试在查询中写这样的东西时,它什么也不返回。 I need to convert to number for calculation.
我需要转换为数字进行计算。 sum up, then again use to char to separate comma.
总结一下,然后再次使用 to char 分隔逗号。
select kpi_a_pk, dept_name,
case when dept_name = 'A' then to_char(kpi_a_1,'999,999,999,999') else null end +
case when dept_name = 'B' then to_char(kpi_a_1,'999,999,999,999') else null end
,to_char(kpi_a_2,'999,999,999,999'),to_char(kpi_a_3,'999,999,999,999')
from KPI where dept_name = 'C'
So if Grid for DEPT A:因此,如果 A 部门的网格:
Grid for DEPT B: B 部门的网格:
Then expected Grid for Dept C should be:那么部门 C 的预期网格应该是:
How can i modify the third grid query to get the values added cell by cell?如何修改第三个网格查询以逐个单元格获取添加的值? In my opinion DA shouldn't be needed.
在我看来,不应该需要 DA。 I tried modifying the query but it doesn't return anything.
我尝试修改查询,但它没有返回任何内容。
I'm not following your logic;我没有遵循你的逻辑; why do you
TO_CHAR
those numbers?你为什么要
TO_CHAR
那些数字? Wouldn't you rather use format mask to display them properly?您不想使用格式掩码正确显示它们吗?
As of problem you have in the 3rd grid which doesn't display the sum:至于你在第三个网格中遇到的问题,它不显示总和:
don't sum strings, as that's what you are doing.不要对字符串求和,因为这就是你正在做的事情。
TO_CHAR(kpi_a_1, ...)
is a string. TO_CHAR(kpi_a_1, ...)
是一个字符串。 That's as if you want to know result of av$#5 + #$fs
.这就好像你想知道
av$#5 + #$fs
的结果。 Sum numbers, not strings对数字求和,而不是字符串
though, if Oracle managed to implicitly convert those values into numbers, it did that (and didn't raise an error).但是,如果 Oracle 设法将这些值隐式转换为数字,它会这样做(并且没有引发错误)。 But, this is what might be bothering you:
但是,这可能会困扰您:
case when dept_name = 'A' then to_char(kpi_a_1,'999,999,999,999') else null end ----
You're adding NULL
if dept_name isn't 'A'
.如果 dept_name 不是
'A'
,则添加NULL
。 Adding NULL
to anything results in null
:添加
NULL
到任何结果null
:
SQL> select 1 + null as result from dual; RESULT ---------- SQL>
Maybe you'd rather use else 0
也许你宁愿使用
else 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.