1

我有一个查询,它给了我所有的记录。现在我想检查所有记录中有多少记录位于这三个条件之间

  1. 小于等于 250,000
  2. 250,000 500,000 之间
  3. 50万及以上

我总共有 6 列。通过减去Credit Dist dt - App Received dt我得到的列working days1,通过减去LO Issued - appr_dec我得到的working days2。在确定了哪些记录属于哪个条件之后,我必须计算每个条件下的所有应用程序,并将应用程序的计数除以working day1working day2。我如何确定哪个应用程序属于哪个条件并继续进行?

查询很长,所以我尝试放置一个虚拟查询来给出一个想法。

select LOSA_APP.app_ref_no AS "App.Ref.No.",
       LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
       column AS "App Received dt",
       column AS "Credit Dist dt",
       column AS "appr_dec",
       column AS "LO Issued" 
from 
    losa_app LOSA_APP
INNER JOIN
    code_branch CODE_BRANCH
ON
    LOSA_APP.attend_branch = CODE_BRANCH.branch_id
.... -- more joins
where
    LOSA_APP.app_status in ('A','R')
and
    .....  --other conditions

对于条件,我必须检查LOSA_EXP_SUMM_Z.group_exp类似LOSA_EXP_SUMM_Z.group_exp <= 250,000, LOSA_EXP_SUMM_Z.group_exp between 250,000 and 500,000,LOSA_EXP_SUMM_Z.group_exp >= 500,000

谢谢

4

1 回答 1

0

You probably need to partition your output by that column/condition, e.g. group 1 - Less than and equal to 250,000, group2..., group 3... Then you may order it within the group. Try using RANK and other analytic functions.

Select * From ( Select empno, deptno, sal , RANK() OVER (PARTITION BY deptno Order by sal) rnk From scott.emp ) /

于 2012-12-05T14:27:04.603 回答