【问题标题】:Select all rows excluding a specific month and year combination in SQL?在 SQL 中选择除特定月份和年份组合之外的所有行?
【发布时间】:2021-07-28 18:44:05
【问题描述】:

This is the table from which 我想选择除 2005 年和第 3 个月之外的所有行。 我尝试了WHERE year_num = 2005 AND month_num = 3,但它排除了所有年份为 2005 的行。

【问题讨论】:

  • WHERE (year_num, month_num) NOT IN ((2005, 3))

标签: mysql sql teradata where-clause


【解决方案1】:

使用NOT:

where not (year_num = 2005 and month_num = 3)

或者:

where year_num <> 2005 or month_num <> 3

注意:这两个也过滤 NULL 值,但可以轻松修改以修复该问题(如果列可以是 NULL)。

【讨论】:

    猜你喜欢
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2017-01-08
    • 1970-01-01
    相关资源
    最近更新 更多