0

我有超过 100k 信息的表格。

ID        FirstName
1           Bob
2           Bob
3           Tom
4           John           
5           John
6           John
..          ....

想要计算多少名称相同的程序,例如它必须像:

FirstName      Count
Bob              2
Tom              1
John             3

请帮我写

4

4 回答 4

2

这是非常基本的 SQL 示例,按列分组 + 聚合结果

select
    FirstName, count(*)
from Table1
group by FirstName
于 2013-08-26T07:06:06.643 回答
1

尝试这个

select FirstName,Count(FirstName) From TableA group by FirstName
于 2013-08-26T07:07:26.970 回答
1

尝试这个

SELECT FirstName, COUNT(*) As Count
FROM YourTable
GROUP BY FirstName
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
于 2013-08-26T07:09:30.183 回答
1
Create Procedure GetCount
as
BEGIN
Select FirstName,Count(*) from tablename group by FirstName 
END
于 2013-08-26T07:14:49.783 回答