【问题标题】:How do i write a sql query that is contingent on 2 columns in one conditional?我如何编写一个取决于一个条件中的 2 列的 sql 查询?
【发布时间】:2020-07-23 18:37:26
【问题描述】:

在名为 usercore 的表上执行以下伪查询:

select average of userscore.points
where (userid = userid)
and ((userscore.year != given year) && (userscore.week != given week))

如何编写一个过滤掉特定周/年列组合的查询?例如,本周是 2020 年的第 29 周。我如何编写一个仅过滤掉 2020 年的第 29 周而不是 2019/2018/2017 等的第 29 周的查询?

【问题讨论】:

    标签: sql database where-clause


    【解决方案1】:

    如何编写一个仅过滤掉 2020 年第 29 周而不是 2019/2018/2017 年等第 29 周的查询?

    这更多是关于布尔逻辑的问题,而不是 SQL。

    假设 given_yeargiven_week 是您查询的参数,您需要类似:

    where not (year = given_year and week = given_week)
    

    你也可以用or来表达:

    where year <> given_year or week <> given_week
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-21
      • 1970-01-01
      • 2023-04-10
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多