【问题标题】:How to sum the columns counts of the same table?如何对同一张表的列数求和?
【发布时间】:2019-11-21 07:48:16
【问题描述】:

我有一个有 4 列的表,我需要对每列的 COUNT 求和。

我正在使用 PostgreSQL。

【问题讨论】:

  • 绝对是基本的,到目前为止你尝试过什么?
  • edit您的问题(通过单击下面的edit 链接)并添加一些sample data 和基于该数据的预期输出。 Formatted textno screen shots。 (edit 您的问题 - 在 cmets 中不要邮政编码或其他信息)
  • 样本数据和期望的结果会有所帮助。 “总和”对您意味着什么?

标签: sql postgresql select count sum


【解决方案1】:
SELECT COUNT(Col1) + Count(Col2) + Count(Col3) + Count(Col4) as Total FROM *Table*

将所有 4 列的计数加在一起。这应该对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2019-02-15
    相关资源
    最近更新 更多