gpt4 book ai didi

sql - 无组计数

转载 作者:IT老高 更新时间:2023-10-28 23:46:29 25 4
gpt4 key购买 nike

我有一个名为 GUYS(ID,NAME,PHONE) 的表,我需要计算有多少人具有相同的名字,同时显示所有这些人,所以我无法将他们分组。示例:

ID NAME  PHONE
1 John 335
2 Harry 444
3 James 367
4 John 742
5 John 654

想要的输出应该是

ID NAME  PHONE COUNT
1 John 335 3
2 Harry 444 1
3 James 367 1
4 John 742 3
5 John 654 3

我该怎么做?我只设法得到很多不同计数的人。

谢谢

最佳答案

使用聚合查询:

select g.ID, g.Name, g.Phone, count(*) over ( partition by g.name ) as Count
from
Guys g;

关于sql - 无组计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4259611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com