MySql计算相同的值

时间:2014-01-22 08:26:28

标签: mysql sql count

我有这张桌子。我的任务是:计算具有相同名字的学生。

我希望它只显示名字,然后显示第一个名字的次数:

像这样: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

1 个答案:

答案 0 :(得分:3)

这是查询

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