count entrys,不同列中的double

时间:2017-07-23 14:48:16

标签: mysql sql count

我正在搜索一个mysql查询,该查询为我提供了连接到大多数服务器的用户的视频,但不包括steamid已经在的服务器。

不确定如何正确描述,因为我不是母语为英语的人。

id  | steamid  | onserveradress
--- | -------- | --------------
1   | steam:11 | 111.111.11.111
2   | steam:11 | 222.222.22.222
3   | steam:22 | 333.333.33.333
4   | steam:11 | 111.111.11.111
5   | steam:33 | 111.111.11.111
6   | steam:44 | 444.444.44.444
7   | steam:44 | 222.222.22.222
8   | steam:11 | 444.444.44.444

所以我希望结果是

steamid  | count
-------- | -----
steam:11 | 3
steam:44 | 2
steam:22 | 1
steam:33 | 1

1 个答案:

答案 0 :(得分:0)

也许你就是在这之后...

SELECT steamid
     , COUNT(DISTINCT onserveradress) total 
  FROM my_table 
 GROUP  
    BY steamid 
 ORDER 
    BY total;