0

我在使用以下 SQL 查询的 where 语句时遇到问题:

select distinct
  [columns]
from ifsapp.customer_order_inv_head coih
left outer join ifsapp.identity_invoice_info iii
  on coih.company = iii.company
  and coih.identity = iii.identity
  and iii.party_type_db = 'CUSTOMER'
left outer join ifsapp.customer_info_address cia
  on coih.identity = cia.customer_id
  and cia.address_id = '1' 
left outer join ifsapp.customer_info_comm_method cicm
  on coih.identity = cicm.customer_id
  and cicm.address_id = '1'
where coih.invoice_date between to_date('&date_from', 'dd/mm/yyyy') and to_date('&date_to',        'dd/mm/yyyy')
  and iii.group_id not in ('1', '2', '3', '4', '5', '6', '7', '8', '9')
  and iii.pay_term_id <> 'SO'
  and ifsapp.fb_dev_utils_api.is_einvoice_customer(coih.identity) = 'FALSE'
  and ifsapp.fb_dev_utils_api.is_edi_customer(coih.identity) = 'FALSE'
  and coih.net_amount >= ('&Value')
  and upper(cicm.name) not like upper(nvl('&Optout', 'blank'))
  and upper(iii.group_id) like upper(nvl('&Cust_Group', '%'))
  and upper(coih.company) like upper(nvl('&Company', '%'))

以上工作正常(如果有点慢),但是我也只想排除iii.group_id = '10'coih.contract not like 'S%'我无法正确使用语法。我尝试了以下方法:

or (coih.contract not like 'S%' and iii.group_id = '10')

非常感激任何的帮助。

4

2 回答 2

0

你是在正确的轨道上。但该where声明是关于要包括的内容,而不是排除的内容。您想包括以下记录:

and (coih.contract like 'S%' or iii.group_id <> '10')

您可能会发现此表格更易于理解:

and not (coih.contract not like 'S%' and iii.group_id = '10')

顺便说一句,这假设这两个变量不采用 NULL 值。

于 2013-05-28T13:53:50.247 回答
0

而不是这个:

OR (coih.contract NOT LIKE 'S%' AND iii.group_id = '10')

尝试这个:

AND NOT (coih.contract LIKE 'S%' AND iii.group_id = '10')

这样,它将查看 group_id 是否等于 10 并且合同不是以“S”开头。

于 2013-05-28T11:31:55.527 回答