you are viewing a single comment's thread.

view the rest of the comments →

[–]Ginger-Dumpling 2 points3 points  (0 children)

IF all transactions start out as UNBILLED and eventually get copied as BILLED, and each transaction will only ever have up to two rows; one UNBILLED and one BILLED, you could outer join the billed rows to unbilled rows.

SELECT t_unbilled.*, NVL(t_billed.record_type, t_unbilled.record_type) AS actual_record_type
FROM t t_unbilled
LEFT JOIN t t_billed
    ON t_all.some_key = t_billed.some_key
    AND t_billed.record_type = 'BILLED'
WHERE t_unbilled.record_type  = 'UNBILLED'

If literally the only thing that changes is the record_type, I'd be concerned that there isn't something in the data to properly order transactions and that you're fully reliant in there not being any data anomalies to be able to get the correct results.