如何使用Oracle PL/SQL实现以下代码

如何使用Oracle PL/SQL实现以下代码,oracle,plsql,Oracle,Plsql,我如何做到以下几点, 我必须使用以下公式检查从最新报表日期算起的最后30天w.r if ((sum of credits for 30 days from the latest statement date w.r. to account/ sum debits for 30 days from the latest statement date w.r. to account) -sum debits for 30 days from the latest statement date w.r

我如何做到以下几点, 我必须使用以下公式检查从最新报表日期算起的最后30天w.r

if ((sum of credits for 30 days from the latest statement date w.r. to account/
sum debits for 30 days from the latest statement date w.r. to account)
-sum debits for 30 days from the latest statement date w.r. to account)>0 then YES else NO
下面是两个不同表中的两列,我需要根据这两列导出每个帐户的公式。以及表A和表B中的账目

STATEMENT_DATE_LATEST; --from TableA
LATEST_BAL_IN_USD; -- from TableB

注意:上面的语句中的:/is除以and-is减号

如果我理解正确,是否需要此帮助

with temp as
  (select a.account,
          sum(case when b.transaction_amount >= 0 then b.transaction_amount end) sum_credits,
          sum(case when b.transaction_amount <  0 then b.transaction_amount end) sum_debits
   from table_a a join table_b b on a.account = b.account
   where b.statement_date > a.statement_date_latest + 30
   group by s.account
  )
select t.account,
       case when (t.sum_credits / t.sum_debits) - t.sum_debits > 0 then 'YES'
            else 'NO'
       end result
from temp t; 

帮助我们帮助您-请分享完整的表格定义和一些示例数据为什么您认为我们需要了解最新的美元余额?你的问题似乎与该领域无关@BobJarvis LATEST_BAL_IN_USD是一列,在表B中有交易金额贷方和借方条目。这是SQL,但OP在标题和标签中添加了PL/SQL,这可能是他们对术语的误解,但我们必须假设他们知道自己的要求。更重要的是,对OP的数据模型和数据:@Littlefoot credits和debits在同一列中,没有贷记符号,数字前面的-交易金额是Debit,那么我们如何根据它计算金额?哦,来吧!我只是想帮忙!:。。。我修改了代码,以便它查看交易金额及其符号。Littlefoot只是把想法告诉了Yogesh,这样他就可以相应地解决他的问题。