英文:
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 BY
与HAVING
一起使用:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论