 
 -- A2
 select *
-from analytics_accounts bac b
-join account_history ah on b.account_record_id = ah.record_id
-join audit_log al on ah.record_id = al.target_record_id and al.change_type = 'INSERT' and table_name = 'ACCOUNT_HISTORY'
+from analytics_accounts b
+join account_history ah on b.account_record_id = ah.target_record_id
+join audit_log al on ah.record_id = al.target_record_id and al.change_type = 'INSERT' and al.table_name = 'ACCOUNT_HISTORY'
 where coalesce(b.created_reason_code, 'NULL') != coalesce(al.reason_code, 'NULL')
 or coalesce(b.created_comments, 'NULL') != coalesce(al.comments, 'NULL')
 or coalesce(b.created_by, '') != coalesce(al.created_by, '')

from analytics_account_transitions bos
left outer join blocking_states bs on bs.record_id = bos.blocking_state_record_id
where coalesce(bs.record_id, 'NULL') != coalesce(bos.blocking_state_record_id, 'NULL')
or coalesce(bs.TYPE, 'NULL') != 'SUBSCRIPTION_BUNDLE'
or coalesce(bs.state, 'NULL') != coalesce(bos.status, 'NULL')
or coalesce(bs.created_date, 'NULL') != coalesce(bos.created_date, 'NULL')
or coalesce(bs.created_date, 'NULL') != coalesce(bos.start_date, 'NULL')
or coalesce(bs.account_record_id, 'NULL') != coalesce(bos.account_record_id, 'NULL')
or coalesce(bs.tenant_record_id, 'NULL') != coalesce(bos.tenant_record_id, 'NULL')
;

-- E4
select *
from analytics_invoice_credits b
left outer join bundles bndl on b.bundle_id = bndl.id
where coalesce(bndl.external_key, 'NULL') != coalesce(b.bundle_external_key, 'NULL')
;

