1

我有这张桌子:

id_user id_user2
1      54
1      53
1      53
1      54
1      54
1      55
2      23
2      23
2      20
2      21
2      25
2      25

我想数一数,每个人id_user有多少与id_user2. 输出应该是:

id_user id_user2    result
1       54          3
1       53          2
1       55          1
2       23          2
2       20          1
2       21          1
2       25          2
4

2 回答 2

4

你必须使用group by子句

select id_user,id_user2, count(1) as result
from userstab
group by id_user,id_user2
于 2013-08-05T11:25:32.340 回答
0

试试这个查询

select id_user,id_user2,count(id_user2) as result
from TABLE_NAME group by id_user2
于 2013-08-05T11:30:06.900 回答