oracle sql条件where语句

oracle sql条件where语句,sql,oracle,where-clause,Sql,Oracle,Where Clause,以下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 out

以下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', '%'))
任何帮助都将不胜感激。

请不要这样:

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

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

通过这种方式,它将检查组id是否等于10,合同是否以“S”开头。

您的思路是正确的。但是
where
语句是关于要包括什么,而不是排除什么。您希望包括以下记录:

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

顺便说一句,这假设这两个变量不具有空值。

我只希望在协定与“S%”不同的情况下返回组id 10,但我希望返回所有其他组id,而不管协定如何。如果组id为10,但排除了所有其他组id,则上述解决方案可以正常运行。正如Gordon已经指定的那样,我看不出有任何理由认为这不起作用,也不起作用(coich.contract不象'S%'和iii.group\u id='10')我要么错过了
而不是…
,要么在我写下我的评论后对答案进行了编辑。我感谢你们两位的帮助。这些答案不太正确,但让我找到了一个解决方案:
而不是(coich.contract LIKE'S%'和iii.group_id='10')
很高兴你们找到了解决方案,很难弄清楚用户想要什么,尤其是当您自己无法运行代码时。我编辑了我的答案,以反映对你有用的东西。
and (coih.contract like 'S%' or iii.group_id <> '10')
and not (coih.contract not like 'S%' and iii.group_id = '10')