求救啊!!!这段MySQL代码怎么改写成Oracle代码啊
小张程序员 2020-04-16 04:42:21 SELECT
t.transaction_id,
MAX(IF ( rn = 1, t.plan_amount_total, NULL )) AS first_plan_amount,
MAX(IF ( rn = 1, t.fully_paid, NULL )) AS first_is_fully_paid,
MAX(IF ( rn = 2, t.plan_amount_total, NULL )) AS second_plan_amount,
MAX(IF ( rn = 2, t.plan_receipt_date, NULL ) ) AS second_receipt_date,
MAX(IF ( rn = 2, t.fully_paid, NULL )) AS second_is_fully_paid,
MAX(IF ( rn = 3, t.plan_amount_total, NULL )) AS third_plan_amount,
MAX(IF ( rn = 3, t.plan_receipt_date, NULL ) ) AS third_receipt_date,
MAX(IF ( rn = 3, t.fully_paid, NULL )) AS third_is_fully_paid,
MAX(IF ( rn = 4, t.plan_amount_total, NULL )) AS four_plan_amount,
MAX(IF ( rn = 4, t.plan_receipt_date, NULL ) ) AS four_receipt_date,
MAX(IF ( rn = 4, t.fully_paid, NULL )) AS four_is_fully_paid,
MAX(IF ( rn = 5, t.plan_amount_total, NULL )) AS fifth_plan_amount,
MAX(IF ( rn = 5, t.plan_receipt_date, NULL ) ) AS fifth_receipt_date,
MAX(IF ( rn = 5, t.fully_paid, NULL )) AS fifth_is_fully_paid
FROM
(SELECT
@r:= case when @transactionId = p1.transaction_id then @r + 1 else 1 end as rn,
p1.transaction_id AS transactionId,
p1.*
FROM
(SELECT
p.transaction_id,
p.plan_amount_total,
p.plan_receipt_date,
IF
( SUM( item.actual_amount ) = p.plan_amount_total, '是', '否' ) AS fully_paid
FROM
yxcw.fin_payment_plan p
INNER JOIN rep_param_project pp ON ( pp.job_id = p_report_log_id AND pp.project_num = p.project_num)
LEFT JOIN yxcw.fin_actual_received_item item ON item.is_deleted = 0
AND item.payment_plan_id = p.id
WHERE
1 = 1
AND p.fund_name_code NOT IN ('FIFT01001','FIFT01004')
AND p.fund_type_code IN ('FIFT01','FIFT02')
GROUP BY
p.id
ORDER BY
p.plan_receipt_date ASC,
p.id ASC ) p1,
(select @r:=0 ,@transactionId:='') b
ORDER BY
p1.transaction_id,
p1.plan_receipt_date
) t
GROUP BY
t.transaction_id