所以我select statement用 an 写了一个outer join,但我遇到了一些逻辑问题。首先是声明:
SELECT DISTINCT ah.ACCOUNT, lr.recall_status, lr.cancel_recall, lr.suit_atty, lb.note_sent, lb.current_atty, 
                  lr.file_date, ah.attorney_id, ah.transaction_date, rle.id_code, ah.rule_id, lr.processed, ah.transaction_code
  FROM legal_bankruptcy lb, legal_recall lr, legal_transaction_review ah, atlas.rlglenty rle
  WHERE ah.ACCOUNT = lb.ACCOUNT
  AND ah.ACCOUNT = lr.ACCOUNT(+)
  AND lb.current_atty = rle.id_code
  AND lr.file_date = (SELECT MAX(file_date) FROM legal_recall WHERE ACCOUNT = ah.ACCOUNT)
  AND ah.rule_id IN (1,2,114,191)
  AND ah.batch_id = p_batch_id
现在这应该是如何工作的,并不是所有的账户都会出现在legal_recall表格中,特别是如果他们的账户没有被召回,但我仍然需要查明是否通过legal_bankruptcy. 我也知道这没有select statement返回任何内容的原因rows是因为这一行:
AND lr.file_date = (SELECT MAX(file_date) FROM legal_recall WHERE ACCOUNT = ah.ACCOUNT)
当我将其注释掉时,我会返回值。不过,我现在遇到的问题是,当有一个帐户时,legal_recall我需要确保我得到了最新的文件。如果我把那条线去掉,那么我可能会得到错误的日期,这会弄乱我的输出。
我在问他们是否可以解决这个问题,或者我是否陷入困境。提前致谢。