我的桌子里有超过100k的信息。
ID FirstName
1 Bob
2 Bob
3 Tom
4 John
5 John
6 John
.. ....
想要计算多少名称相同的程序,例如它必须如下:
FirstName Count
Bob 2
Tom 1
John 3
请帮我写一下
答案 0 :(得分:2)
这是非常基本的SQL示例,group by column + aggregating results
select
FirstName, count(*)
from Table1
group by FirstName
答案 1 :(得分:1)
试试这个
select FirstName,Count(FirstName) From TableA group by FirstName
答案 2 :(得分:1)
试试这个
SELECT FirstName, COUNT(*) As Count
FROM YourTable
GROUP BY FirstName
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
答案 3 :(得分:1)
Create Procedure GetCount
as
BEGIN
Select FirstName,Count(*) from tablename group by FirstName
END