oracle SQL中的每个循环都要显示动态列

时间:2018-06-19 07:56:05

标签: sql oracle

我是SQL的新手,请帮我解决下面的查询

SELECT DISTINCT
       ROG.GROUPID,
       CAPA1.PERC,
       CAPA1.TPTID
FROM AGREGATEDPOLICY APO
INNER JOIN REINSURANCEOPERATION RO ON APO.AGREGATEDPOLICYID = RO.AGREGATEDPOLICYID
INNER JOIN REINSURANCEOPERATIONGROUPINFO ROG ON RO.OPERATIONID = ROG.OPERATIONID
INNER JOIN (SELECT RIC.GROUPID GID, RIP.PERCENTAGE PERC, RIP.THIRDPARTYID TPTID
              FROM RI_REINSURANCECONTRACT RIC
        INNER JOIN RI_CONTRACTCOMPONENT RICC ON RICC.MAINID = RIC.RCID
        INNER JOIN RI_CCPARTICIPATION RICP ON RICP.CCID = RICC.CCID
        INNER JOIN RI_PARTICIPATION RIP ON RIP.PARTICIPATIONID = RICP.PARTICIPATIONID
        INNER JOIN RI_EXCESSLOSS RIE ON RIE.EXCESSLOSSID = RICC.CCID
        INNER JOIN EXCESOPERDIDA EXP ON EXP.PK = RIE.EXCESSDCOID
             WHERE RIC.REINSURANCECONTRACTTYPE = 0
               AND RICC.TYPE = 'LossExcess') CAPA1 ON ROG.GROUPID = CAPA1.GID

现在每个 GROUPID 可能有多个 THIRDPARTYID 。我希望将每个 THIRDPARTYID PERCENTAGE 乘以25。

例如,如果输出是

GROUPID PERCENTAGE THIRDPARTYID
2824    0.4        824603
2824    0.4        824500
2824    0.5        824603
2824    0.2        824601
2824    0.5        824500

我想将输出显示为 RESULT1 ..... n (根据下面的THIRDPARTYID动态更改n

GROUPID  RESULT1  RESULT2  RESULT3  RESULT4  RESULT5
2824     10       10       12.5     5        12.5

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以在选择中添加此类计算:

SELECT DISTINCT
       ROG.GROUPID,
       CAPA1.PERC,
       CAPA1.TPTID,CAPA1.PERC*25 as RESULT