如何根据 Postgres 中的一个值进行计数?

How to count based on one value in Postgres?

我有以下数据,我想对 JobName 进行分组,但我需要所有数据列。

JobName  rule  name …….
Job-A     1     PDF
Job-A     1     PDF
Job-A     1     PDF
Job-B     2     ADF
Job-B     2     ADF
Job-C     3     OPS
Job-D     4     NPS
Job-D     4     NPS
Job-D     4     NPS
Job-D     4     NPS

结果应该是

JobName  rule  name  ….  count
Job-A     1     PDF     3
Job-B     2     ADF     2
Job-C     3     OPS     1
Job-D     4     NPS     4

除非我遗漏了某些要求,否则您只需要按所有三列进行聚合,然后计算每组的数量:

SELECT JobName, rule, name, COUNT(*) AS count
FROM yourTable
GROUP BY JobName, rule, name;