2014-01-22 106 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