【问题标题】:Sum Only Specific Values in a Column仅对列中的特定值求和
【发布时间】:2021-05-22 23:59:35
【问题描述】:

我在 MS Access 中有一个查询,显示以下信息:

ID Count Complete_Type
UserA 10 Replied
UserA 20 Sent
UserA 30 Closed without Response

我想创建一个新的 SQL 查询,它使用上面的查询,但总和是每个唯一用户的计数,只有 Completed Type 的“Replied”和“Closed without Response”。例如,新查询将显示如下:

ID Count
UserA 40

有人能帮我写这个查询吗?

【问题讨论】:

    标签: mysql sql sum wizard exclude-constraint


    【解决方案1】:

    您可以使用where 子句:

    select id, sum(count)
    from t
    where Complete_Type in ('Replied', 'Closed without Response')
    group by id;
    

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 1970-01-01
      • 2013-03-02
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多