Ask the redesign please

It is always 0, because at most only disp1 or disp2 returns all the lines and is probably not the most effective solution anyway.  How it should be redesigned?

Select nvl (count (distinct disp1.sak_acct_rec), 0),

NVL (Sum (decode(DISP1.ind_debit,'D',DISP1.) AMT *-1,' IT, DISP1. AMT, DISP1. (AMT)), 0),

NVL (count (distinct disp2.sak_acct_rec), 0),

NVL (Sum (decode(DISP2.ind_debit,'D',DISP2.) AMT *-1,' IT, DISP2. DISP2 AMT. (AMT)), 0)

from (select distinct disp.sak_acct_rec, disp.amt, xref.sak_claim, disp.ind_debit

of cz05g0.t_tpl_ar_disps disp,

cz05g0.t_tpl_ar_clm_xref xref,

-aim01.t_clm_pgm_xref pgm,

cz05g0.t_clm_pgm_xref pgm,

cz05g0.t_hist_directory hist,

help cz05g0.t_cde_aid,

code cz05g0.t_tpl0101m_tmp

where disp.amt > 0

- and disp.dte_added between: begin_date and: end_date

and disp.sak_acct_rec = xref.sak_acct_rec

and pgm.sak_claim = xref.sak_claim

and xref.sak_claim = hist.sak_claim

and to_char (substr (hist.num_icn_fl, 1, 1))! = "7"

and pgm.sak_cde_aid = aid.sak_cde_aid

and aid.cde_aid_category between code.cdefrom and code.cdeto

) disp1,.

(select distinct nvl (disp.sak_acct_rec, 0) as sak_acct_rec, nvl (disp.amt, 0) as amt,)

NVL (xref.sak_claim, 0), like sak_claim, nvl (disp.ind_debit, 0) as ind_debit

-Select distinct nvl (disp.sak_acct_rec, 0), nvl (disp.amt, 0), nvl (xref.sak_claim, 0), nvl (disp.ind_debit, 0)

of cz05g0.t_tpl_ar_disps disp,

cz05g0.t_tpl_ar_clm_xref xref,

-aim01.t_clm_pgm_xref pgm,

cz05g0.t_clm_pgm_xref pgm,

cz05g0.t_hist_directory hist,

help cz05g0.t_cde_aid,

code cz05g0.t_tpl0101m_tmp

where disp.amt > 0

- and disp.dte_added between: begin_date and: end_date

and disp.sak_acct_rec = xref.sak_acct_rec

and pgm.sak_claim = xref.sak_claim

and xref.sak_claim = hist.sak_claim

and to_char (substr (hist.num_icn_fl, 1, 1)) = "7"

and pgm.sak_cde_aid = aid.sak_cde_aid

and aid.cde_aid_category between code.cdefrom and code.cdeto

) disp2;

Remove the filter condition '7' and include it in the select clause with an aggregate function, like this:

Select nvl (count (distinct (case when to_char (substr (hist.num_icn_fl, 1, 1))! = '7' disp1.sak_acct_rec then end), 0),)

....

NVL (count (distinct (case when to_char (substr (hist.num_icn_fl, 1, 1)) is '7' disp2.sak_acct_rec then end), 0),)

....

of cz05g0.t_tpl_ar_disps disp,

cz05g0.t_tpl_ar_clm_xref xref,

-aim01.t_clm_pgm_xref pgm,

cz05g0.t_clm_pgm_xref pgm,

cz05g0.t_hist_directory hist,

help cz05g0.t_cde_aid,

code cz05g0.t_tpl0101m_tmp

where disp.amt > 0

- and disp.dte_added between: begin_date and: end_date

and disp.sak_acct_rec = xref.sak_acct_rec

and pgm.sak_claim = xref.sak_claim

and xref.sak_claim = hist.sak_claim

and pgm.sak_cde_aid = aid.sak_cde_aid

and aid.cde_aid_category between code.cdefrom and code.cdeto

Tags: Database

Similar Questions

Maybe you are looking for

  • How can I recover the address book from a previous installation?

    I had to reinstall Thunderbird on my PC. When I did, all my previous entries to address book are missing. Is it possible to recover?

  • Hotmail untrusted connection, why?

    All this while I've been using Hotmail and that's fine. Until recently, after that I connect to Hotmail, it will tell "We can't connect to Outlook.com right now. Please try again later." Then, when I update he says "This connection is Untrusted". You

  • iTunes does not find devices in Windows 10

    I installed the latest version of iTunes on my new laptop running Windows 10.  When I connect devices, nothing shows up on itunes.   No devices and 'peripheral' is not in the drop-down list.  I uninstalled and reinstalled without success.  When I con

  • Alternate click right key missing keyboard

    Hello I am currently using HP N012 TX. The keyboard for this laptop does not have a right click menu button! Na purchasig not see it, big mistake. I'm addicted to the use of this key. Y at - he replaced anyway I can get any other button or any other

  • I can't figure out how to get a reminder to pop about an event, I put on my calendar in windows live

    I'm used to using microsoft works calendar XP.  When I put a windows live event calendar it has an icon for reminder on top, but it is dimmed, and I can't figure out how to set a reminder.  I want more that just a moment email reminder a reminder pop