Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 第1列的数据总和,其中介于第2列的范围之间_Oracle_Plsql - Fatal编程技术网

Oracle 第1列的数据总和,其中介于第2列的范围之间

Oracle 第1列的数据总和,其中介于第2列的范围之间,oracle,plsql,Oracle,Plsql,我是PL-SQL的新手,因此需要一些帮助 表1包括: LoanIntersestRates ------------------ 4.5 4.0 3.5 3.0 2.5 表2包括: ActualInterestRate LoanAmt ----------------------------- 4.6 356258.00 4.7 387958.25 2.6 485658.25 3.65

我是PL-SQL的新手,因此需要一些帮助

表1包括:

LoanIntersestRates
------------------
4.5
4.0
3.5
3.0
2.5
表2包括:

ActualInterestRate  LoanAmt
-----------------------------
4.6                 356258.00
4.7                 387958.25
2.6                 485658.25
3.65                500562.00
4.1                 434135.25
2.65                756254.02
4.5                 286325.02
我需要做的是得到一个贷款总额,其中RealizeInterestrate正好是表1中的内容。 此外,还需要对loadAmts进行汇总,其中RealizeInterestrate比每个贷款利率高1-50分,比每个贷款利率高50-100分,比每个贷款利率高100+分


在此方面的任何帮助都将不胜感激。提前谢谢

您好,我对您的问题有些误解,但请检查我的sql

with t1 as
 (select 4.5 as lir
    from dual
  union all
  select 4.0
    from dual
  union all
  select 3.5
    from dual
  union all
  select 3.0
    from dual
  union all
  select 2.5 from dual),
t2 as
 (select 4.6 as air, 356258.00 as la
    from dual
  union all
  select 4.7, 387958.25
    from dual
  union all
  select 2.6, 485658.25
    from dual
  union all
  select 3.65, 500562.00
    from dual
  union all
  select 4.1, 434135.25
    from dual
  union all
  select 2.65, 756254.02
    from dual
  union all
  select 4.5, 286325.02 from dual),
t1_d as
 (select lir as lir_low, lead(lir) over(order by lir) as lir_high from t1)
select t1_d.lir_low, sum(la) as sum_la
  from t1_d, t2
 where t2.air >= t1_d.lir_low
   and ((t2.air < t1_d.lir_high) or (t1_d.lir_high is null))
 group by t1_d.lir_low

如果要获得表1中提到的费率总和,请使用以下查询

select lr.interest,sum(amount) from loaninterestrates lr, loaninterestamounts la
where lr.interest = la.interest
group by lr.interest
对于步骤-2,要查找范围的总和,请使用

select la1.intrange,sum(la1.amount)from
(
select la.interest,la.amount,case when Remainder(la.interest*10,10) < 0 or Remainder(la.interest*10,10) = 5 
                  then to_char(FLOOR(la.interest) + 0.5) || '-' || to_char(FLOOR(la.interest) + 1.0)
            else to_char(FLOOR(la.interest)) || '-' || to_char(FLOOR(la.interest) + 0.5 )
            end as intrange
        from loaninterestamounts la

  ) la1
 group by la1.intrange

SQLFIDLE here:

你能用一个例子解释一下1-50,50-100LoanInterestRestate=4.5点吗?现在我需要对LoanAmts求和,其中RealizeInterestrate比4.5高出1-50点,所以4.5到5.0之间的任何东西,比如4.6,4.7,4.8,4.9等等。@user3111964到目前为止你都尝试了什么?给我们看看你的代码。对不起,如果我解释得不够好,你误解了什么?现实的互动将是动态的。我不知道这些值是什么。问题是,我不明白1-50对我来说意味着什么,它看起来像1.5,例如4.5->4.5-6.0,所以我的sql我只找到所有的句点,用于数据检查t1\u d子选择