【发布时间】:2013-09-06 14:55:27
【问题描述】:
所以我写了一个select statement 和一个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 时,我需要确保获得最新的文件。如果我把那条线去掉,那么我可能会得到错误的日期,这会弄乱我的输出。
我在问他们是否可以解决这个问题,或者我是否陷入困境。提前致谢。
【问题讨论】:
标签: sql oracle outer-join