2014-01-22 116 views
0

我有这张表。我的任务是这样的:统计具有相同名字的学生。MySql计数相同的值

我想让它显示我只是姓,然后名字是多少次发现:

这样的:bob | 2

id  firstN lastN  group grade tax  gender year university 
9  Alyson Hanniga 112  1  0  female 1  UTC 
5  Barney Stinson 111  4  0  male 1  UBB 
8  Bob  Saget  111  6  900  male 3  UBB 
14  Bob  Bob  112  10  250  male 1  UBB 
11  Cobie Smulder 111  9  200  female 1  Dragos Voda 
7  David Henrie  112  9  0  male 1  Dragos Voda 
12  Jason Segel  112  10  150  male 1  UTC 
13  Josh  Radnor  112  7  0  male 2  Dragos Voda 
4  Lily  Aldrin  112  5  400  female 1  UBB 
6  Lyndsy Fonseca 113  10  0  female 3  UTC 
2  Marshal Eriksen 112  10  100  male 2  UTC 
10  Neil  Patrick 112  7  0  male 3  Dragos Voda 
1  Robin Scherba 111  10  0  female 1  UBB 
3  Ted  Mosby  112  8  0  male 2  UBB 
+0

PFF查询。这很愚蠢。我怎样才能编辑这个和复制/粘贴一张桌子..它不会让我发布图像:( – user3222552

+0

要做到这一点,你需要在这个网站上获得一些声誉。 /meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites) –

+0

从学生组中选择firstName,count(*)by firstName having count(*)> 1; – user3222552

回答

3

这里是

select FirstName,count(*) from tblStudent group by FirstName