简体   繁体   English

Oracle 第三网格中 2 个交互式网格列的顶点总和

[英]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.

相关问题 Oracle Apex Interactive Grid 根据条件禁用 ROW - Oracle Apex Interactive Grid Disable a ROW based on a condition 如何在 Oracle APEX Interactive 网格报告中维护运行计数器 - How to maintain a running counter within an Oracle APEX Interactive grid report 如何在 sql(apex oracle)中的交互式网格上获取 mailto - How to get mailto on interactive grid in sql (apex oracle) Oracle APEX:根据交互式网格中的更改更新表 - Oracle APEX: Update Table based on changes in an Interactive Grid Oracle APEX:将主键分配为交互式网格 ROWID,在 SQL 查询中使用 select 交互式网格 ROWID - Oracle APEX: Assign primary key as interactive grid ROWID, Use select Interactive Grid ROWID in SQL query 如何仅使用 sql 和 oracle APEX 中可用的内容在 apex oracle 的交互式网格中实现 select 列表? - How can I implement a select list in apex oracle's interactive grid using only sql and what's available in oracle APEX? APEX 交互式网格交替行 Colors - APEX Interactive Grid Alternating Row Colors 如何在交互式网格上显示所有数据,然后使用 oracle_apex 上的穿梭过滤器减少它? - How do I show all of the data on an interactive grid and then reduce it with shuttle filters on oracle_apex? 如何在 APEX 20.1 的交互式网格中获取 select 列表中的唯一值 - How to get unique values in select list in interactive grid in APEX 20.1 Oracle APEX 交互式报告未更新 - Oracle APEX Interactive Report Not Updating
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM