xs.t_s_contract_m t--销售合同号
WL.T_I_SETTLE_D m--销售合同号,结算清单号
wl.t_i_invoice c--发票号,结算清单号
c表结算清单号(t表和m表用销售合同号得到结算清单号) == 发票号
distinct
应用到多个字段的时候,其应用的范围是其后面的所有字段,而不只是紧挨着它的一个字段,而且distinct
只能放到所有字段的前面,并且再oracle中,distinct 只能用在最左边。
IN 操作符
IN 操作符允许我们在 WHERE 子句中规定多个值。
SQL IN 语法
列:SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...)
IN 操作符实例
现在,我们希望从上表中选取姓氏为 Adams 和 Carter 的人:
我们可以使用下面的 SELECT 语句:
列:SELECT * FROM Persons WHERE LastName IN ('Adams','Carter')
select * from xs.t_s_contract_m t
where 1 = 1
AND exists
(select 1
from wl.t_i_invoice c
where c.seg_no = t.seg_no
and c.settle_id in
(select distinct m.settle_id
from WL.T_I_SETTLE_d m
where m.seg_no = t.seg_no
and m.s_contract_id = t.contract_id)
and c.invoice_num like '%' || 'IS140400916' || '%')
AND exists (select 1 from xs.t_s_settle_d a
where a.seg_no = t.seg_no
and a.contract_id = t.customer_id)
--and a.settle_id >= #settle_begin_id#