【问题标题】:SQL: How to exclude only the criteria if the 2 criteria are met and not both separately within multiple where?SQL:如果两个条件都满足而不是在多个where中单独排除,如何仅排除条件?
【发布时间】:2020-08-26 09:44:00
【问题描述】:
Select * 
FROM SOME_TABLE
where Variable_1 in (1,2,3,4)
and not (Variable_1 in (1) and Variable_2<75000)
 

所以我希望输出中包含变量 1、2、3、4,但排除所有 variable_1=1 AND

我使用 netezza SQL。

【问题讨论】:

  • 我只需要将两个变量组合排除,同时单独保存!您的查询必须严格执行此操作。 fiddle。在其他地方搜索错误。
  • 请提供样本数据和期望的结果。目前尚不清楚您真正想要完成什么。

标签: sql netezza


【解决方案1】:

使用不存在:

Select * 
FROM SOME_TABLE A
where Variable_1 in (1,2,3,4)
and not EXISTS 
(
 SELECT 1 FROM SOME_TABLE B WHERE 
 A.PRIMARYKEY = B.PRIMARYKEY 
 AND Variable_1 in (1) 
 and Variable_2<75000
);

【讨论】:

  • 不需要 - 与源查询相同,但更复杂。
猜你喜欢
  • 2022-10-24
  • 2015-01-25
  • 2021-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多