F59c10b458e4212b941ba215422266ce

Actually it's not PHP. And I'm not a programmer. Thanks for any advice.

select rrr.account_number,
       summa,
       to_char(to_date('19570101', 'YYYYMMDD') + max(rrr.lst_pay_dn),
               'YYYYMMDD')
  from (select account_number, sum(xamount) summa
          from (select account_number, r.xamount
                  from rdcho r
                 where trncde = 6722
                   and xstatus <> 'S'
                   and ((r.ledger_dn > 18992 and r.ledger_dn < 19024 and
                       r.lst_pay_dn < 19024 and r.out_amt = 0) or
                       (r.lst_pay_dn > 18992 and r.lst_pay_dn < 19024 and
                       r.out_amt = 0 and r.ledger_dn < 18993))
                   and account_number in
                       ('180005753763', '192002567023', '192002898856',
                        '192003121600 ')
                 order by account_number, ledger_dn)
         group by account_number) rr,
       rdcho rrr
where rrr.account_number = rr.account_number
   and rrr.lst_pay_dn > 18992
   and rrr.lst_pay_dn < 19024
   and xstatus <> 'S'
   and trncde = 6722
group by rrr.account_number, summa

Refactorings

No refactoring yet !

43b2ca65e7a2cadf849adf103e6c066d

iTony

March 13, 2009, March 13, 2009 22:52, permalink

No rating. Login to rate!

This looks rather complicated and not really readable.
What do you try to do with the query?
and what DBMS is being used (Access, MySQL, Oracle, or other one)?

Your refactoring





Format Copy from initial code

or Cancel