假设我在表 X 中有数据:
id assign team
----------------------
1 hunkim A
1 ygg A
2 hun B
2 gw B
2 david B
3 haha A
我想知道每个 id 有多少分配。我可以使用:
select id, count(distinct assign) from X group by id order by count(distinct assign)desc;
它会给我一些东西:
1 2
2 3
3 1
我的问题是如何获得所有分配计数的平均值?
另外,现在我想知道每支球队的人数。所以我想得到类似的东西:
team assign_avg
-------------------
A 1.5
B 3
提前致谢!