select distinct f.Account_code__C,
case when a.Account_code__C<>'' then 'Y' else 'N' end AS DQ_TOBE,
case when b.Account_code__C<>'' then 'Y' else 'N' end AS DQ_CURRENT
from (
SELECT Account_code__C FROM GODS.DQ_TOBE
union
SELECT Account_code__C FROM GODS.DQ_CURRENT
) f
left join GODS.DQ_TOBE a on a.Account_code__C=f.Account_code__C
left join GODS.DQ_CURRENT b on b.Account_code__C=f.Account_code__C
以下代码应为您提供MS SQL或MySQL的结果: