我有两个选择语句,我需要输出第一个选择记录,另一个应该接收选择1不输出的记录。第二个选择不应该包含选择1的数据。这是我的代码
select b.tcl_tcserno, b.tcl_clmcode, b.tcl_clname, c.prd_desc, e.eqt_desc,
b.tcl_conamount, b.tcl_intrate, f.numirp_minrate, f.dblirp_intrate,
b.tcl_prdcode, e.eqt_type
FROM leaseinfo.trn_ira_intreductapproval a,
leaseinfo.tbltrialcalculation b,
corpinfo.tblproduct c,
leaseinfo.tbltrialequipment d,
leaseinfo.tblequipmenttype e,
leaseinfo.ref_irp_inerestratepara f
WHERE a.numira_tcserno = b.tcl_tcserno
AND b.tcl_prdcode = c.prd_code
AND b.tcl_tcserno = d.teq_tcserno
AND b.tcl_prdcode = e.eqt_prdcode
AND d.teq_eqttype = e.eqt_type
AND b.tcl_prdcode = f.strirp_productcode
AND d.teq_eqttype = f.strirp_eqpttype
AND a.strira_status = 'E'
AND (f.numirp_minrate - b.tcl_intrate)<
(SELECT g.intds_uplim
FROM glinfo.ref_tblintratefordesignation g
WHERE g.intds_designation IN (
SELECT s.str_off_type
FROM dpg.inf_responsible_maildetails s
WHERE s.str_user_code = '10020336'))
and (b.tcl_prdcode='LE' OR b.tcl_prdcode='UV' OR b.tcl_prdcode='HP')
and (e.EQT_TYPE='2' OR e.EQT_TYPE='9' OR e.EQT_TYPE='15' OR e.EQT_TYPE='17' OR e.EQT_TYPE='21' OR e.EQT_TYPE='23' OR e.EQT_TYPE='25' OR e.EQT_TYPE='28' OR e.EQT_TYPE='30')
ORDER BY b.tcl_tcserno
union all
SELECT b.tcl_tcserno, b.tcl_clmcode, b.tcl_clname, c.prd_desc, e.eqt_desc,
b.tcl_conamount, b.tcl_intrate, f.numirp_minrate, f.dblirp_intrate,
b.tcl_prdcode, e.eqt_type
FROM leaseinfo.trn_ira_intreductapproval a,
leaseinfo.tbltrialcalculation b,
corpinfo.tblproduct c,
leaseinfo.tbltrialequipment d,
leaseinfo.tblequipmenttype e,
leaseinfo.ref_irp_inerestratepara f
WHERE a.numira_tcserno = b.tcl_tcserno
AND b.tcl_prdcode = c.prd_code
AND b.tcl_tcserno = d.teq_tcserno
AND b.tcl_prdcode = e.eqt_prdcode
AND d.teq_eqttype = e.eqt_type
AND b.tcl_prdcode = f.strirp_productcode
AND d.teq_eqttype = f.strirp_eqpttype
AND a.strira_status = 'E'
ORDER BY b.tcl_tcserno
我认为不会在这方面工作。但我不知道如何处理它。任何帮助将不胜感激
答案 0 :(得分:1)
这将使用set notation完成工作。假设两个查询中的相同列都可以工作
With dat1 as (....),
Dat2 as (....)
Select * from dat1 Union all
(
Select * from dat2 except select * from dat1
)