【问题标题】:Exclude from resultset based on condition根据条件从结果集中排除
【发布时间】:2021-10-21 06:15:45
【问题描述】:

给定下表FOO;

| Org | Status |
| X   | CLOSED |
| X   | OPEN   |
| Y   | OPEN   |
| Y   | CLOSED |

如何选择所有记录 除了 org = Y and status = CLOSED

所以结果集看起来像:

| Org | Status |
| X   | CLOSED |
| X   | OPEN   |
| Y   | OPEN   |

【问题讨论】:

  • 哪里没有(org = Y 和 status = CLOSED)
  • or, where org y or status closed
  • 这会变得更加复杂,以防 Org 或 Status 可以为空。

标签: sql postgresql


【解决方案1】:

您可以通过以下任一方式执行此操作:

WHERE (org, status) <> ('Y','CLOSED')
WHERE NOT (org = 'Y' AND status = 'CLOSED')

【讨论】:

    【解决方案2】:
    select * from Table where Org != 'Y' and Status != 'CLOSED'
    

    【讨论】:

    • 这也可以,但我只能接受一个答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 2018-12-27
    相关资源
    最近更新 更多