我有下一个问题:
如果你看到图像,我想要加或减值,但老实说,我不知道如何开始?

这就是我如何得到这个结果的
select position, position_1, TIPO_RESUMEN, CONCEPT, to_char(NVL(VALUE,0) ,'FM999G999G999G999G990D00', 'NLS_NUMERIC_CHARACTERS='',.''') as VALUE
from (
SELECT 1 position, 10 position_1, 'Expense' TIPO_RESUMEN, 'Expected expense' CONCEPT ,sum(IMP_GA_GU) VALUE from table_1 tg where UPPER(tg.cod) = 'USER_1' and tg.cod_fol = :P10_FOL and tg.prod_cuad = :P10_PROD and tg.fecha_inicio = :P10_FEC_INI and tip_ga = 'PREVISTO'
union
SELECT 2 position, 20 position_2, 'Expense' TIPO_RESUMEN, 'Unforeseen expense' CONCEPT ,sum(IMP_GA_GU) VALUE from table_2 tp where UPPER(tp.cod) = 'USER_1' and tp.cod_fol = :P10_FOL and tp.prod_cuad = :P10_PROD and tp.fecha_inicio = :P10_FEC_INI and tp.tip_ga = 'NO_PREVISTO'
union
SELECT 3 position, 30 position_3, 'Expense' TIPO_RESUMEN, 'Total' CONCEPT , 0 VALUE from dual
);我需要总价值是(预期费用+意外费用)的总和
有人能帮我吗?
问候
发布于 2020-05-21 15:05:56
因为它是关于Oracle Application Express的,所以我建议您让Apex来做这项工作;它完全有能力做到这一点。多么?只需创建一个报告(经典的或交互式的,无关紧要)。
重要的是,你应该--以某种方式--知道哪些值是正的,哪些是负的。
如果您将它们存储在一个表中,效果会更好。如果不是,则使用CASE,这样屏幕上的值就会真正显示出来(正/负)。然后:
value columnvalue列的属性并选中"Compute sum”属性很简单,不是吗?
如果你选择手动做所有的事情,那么,为了得到一个有问题的结果,这将是大量的编码/努力。你知道Apex在主页上写了什么吗?
构建企业应用的速度提高了20倍,代码减少到原来的1/100
我建议你这么做。
发布于 2020-05-21 20:27:48
您可以使用CTE,然后使用union all。
with cte as (
select 1 as position, 10 as position_1, 'Expense' as TIPO_RESUMEN, 'Expected expense' as CONCEPT , sum(IMP_GA_GU) as VALUE
from table_1 tg
where UPPER(tg.cod) = 'USER_1' and tg.cod_fol = :P10_FOL and tg.prod_cuad = :P10_PROD and tg.fecha_inicio = :P10_FEC_INI and tip_ga = 'PREVISTO'
union all
select 2 as position, 20 as position_2, 'Expense' as TIPO_RESUMEN, 'Unforeseen expense' as CONCEPT, sum(IMP_GA_GU) as VALUE
from table_2 tp
where UPPER(tp.cod) = 'USER_1' and tp.cod_fol = :P10_FOL and tp.prod_cuad = :P10_PROD and tp.fecha_inicio = :P10_FEC_INI and tp.tip_ga = 'NO_PREVISTO'
)
select cte.*
from cte
union all
select 3 as position, 30 as position_3, 'Expense' as TIPO_RESUMEN, 'Total' as CONCEPT , sum(value)
from ctehttps://stackoverflow.com/questions/61928928
复制相似问题