報錯前:
select
(select m.contract_subid
from xs.T_S_CONTRACT_D m
where m.seg_no = d.seg_no
and m.contract_subid = d.contract_subid) "dd_contract_subid"
,(select m.spec
from xs.T_S_CONTRACT_D m
where m.seg_no = d.seg_no
and m.contract_id = d.contract_id) "dd_spec"
from xs.T_S_SETTLE_M a, xs.t_s_settle_d d
where 1=1
and a.seg_no = d.seg_no
and a.settle_id = d.settle_id
修改後:
select
(select m.contract_subid
from xs.T_S_CONTRACT_D m
where m.seg_no = d.seg_no
and m.contract_id = d.contract_id
and m.contract_subid = d.contract_subid) "dd_contract_subid"
,(select m.spec
from xs.T_S_CONTRACT_D m
where m.seg_no = d.seg_no
and m.contract_id = d.contract_id
and m.contract_id = d.contract_id) "dd_spec"
from xs.T_S_SETTLE_M a, xs.t_s_settle_d d
where 1=1
and a.seg_no = d.seg_no
and a.settle_id = d.settle_id
因爲xs.T_S_CONTRACT_D和 xs.t_s_settle_d 都是子表,直接用 '合同號' 關聯自然就出現都行信息,所以在加上一個 '合同子項號' 就沒問題了
子查詢注意你加的關聯條件,避免不存在的問題