cf$_recovery_officer recovery_officer,
cf$_recovery_officer_name recovery_officer_name,
cf$_recovery_zone recovery_zone_code,
cf$_recovery_zone_name recovery_zone_name
FROM c_recovery_officer_history_clv t1
INNER JOIN
(
SELECT cf$_order_no order_no, MAX(ROWID) AS MAX_ROWID
FROM c_recovery_officer_history_clv
GROUP BY cf$_order_no
) t2
ON cf$_order_no = t2.order_no AND t1.ROWID = t2.MAX_ROWID
select t.order_no,
t.changed_date,
t.recovery_officer,
t.recovery_officer_name,
t.recovery_zone_code,
t.recovery_zone_name
from (select cf$_order_no order_no,
cf$_changed_date changed_date,
cf$_recovery_officer recovery_officer,
cf$_recovery_officer_name recovery_officer_name,
cf$_recovery_zone recovery_zone_code,
cf$_recovery_zone_name recovery_zone_name,
row_number() over (partition by cf$_order_no order by cf$_changed_date desc) as seqnum
from c_recovery_officer_history_clv
) t
where seqnum = 1;
SELECT cf$_order_no order_no,
cf$_changed_date changed_date,
cf$_recovery_officer recovery_officer,
cf$_recovery_officer_name recovery_officer_name,
cf$_recovery_zone recovery_zone_code,
cf$_recovery_zone_name recovery_zone_name
FROM c_recovery_officer_history_clv h1
WHERE to_date(cf$_changed_date,'dd-mon-rr') between start_date_ AND end_date_
AND NVL(cf$_recovery_officer,'%') LIKE NVL(RO_,'%')
AND NVL(cf$_recovery_zone,'%') LIKE NVL(ZONE_,'%')
AND (cf$_order_no, cf$_changed_date) = ( SELECT cf$_order_no, MAX(cf$_changed_date)
FROM C_RECOVERY_OFFICER_HISTORY_CLV h2
WHERE h2.cf$_order_no=h1.cf$_order_no
AND to_date(cf$_changed_date,'dd-mon-rr') between start_date_ AND end_date_
AND NVL(cf$_recovery_officer,'%') LIKE NVL(RO_,'%')
AND NVL(cf$_recovery_zone,'%') LIKE NVL(ZONE_,'%')
GROUP BY cf$_order_no
)
No comments:
Post a Comment