查找完成过一次以上流程的项目数量。

huangapple go评论73阅读模式
英文:

Find the number of items that completed a process more than once

问题

| 联系人 | 计数 |
| -------- | -------------- |
| Jerry    | 2 |
| Anna| 2 |
| Richard| 3 |

这是可通过SQL/PostgreSQL实现的查询结果。感谢!

英文:
Contact Step
Jerry registration
Mike registration
Jerry complete
Karl registration
Richard registration
Richard complete
Jerry registration
Jerry complete
Mike complete
Matthew registration
Matthew complete
Richard registration
Richard complete
Anna registration
Anna complete
Richard registration
Karl complete
Richard complete
Anna registration
Anna complete

The table above is a depiction of a software registration process. Registration indicates that the contact is in the registration process and complete mena that they have completed it.

I'd like to know the number of contacts that completed the registration more than once and how many times they completed it.

So the queried results should look like this:

Contact Count
Jerry 2
Anna 2
Richard 3

How is this achievable with SQL/Postgresql. Thanks

答案1

得分: 2

你应该在GROUP BYHAVING一起使用:

SELECT
T.Contact,
COUNT(*) 
 FROM
YOUR_TABLE T 
WHERE T.step='complete'
GROUP BY T.Contact
HAVING COUNT(*)>1
英文:

You should be using the GROUP BY along with HAVING

SELECT
T.Contact,
COUNT(*) 
 FROM
YOUR_TABLE T 
WHERE T.step='complete'
GROUP BY T.Contact
HAVING COUNT(*)>1

huangapple
  • 本文由 发表于 2023年7月13日 22:07:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定