有谁知道怎么找?我有 3 列
1-身份证
2 - 用户名
3-IP
样本数据为:
+----+-----------+----------------+
| id | username | ip |
+----+-----------+----------------+
| 1 | John | 127.0.0.1 |
| 2 | John | 127.0.0.1 |
| 3 | John | 127.0.0.1 |
| 4 | John | 127.0.0.1 |
| 5 | John | 127.0.0.1 |
| 6 | John | 127.0.0.2 |
| 7 | John | 127.0.0.2 |
| 8 | John | 127.0.0.3 |
| 9 | John | 127.0.0.1 |
| 10 | John | 127.0.0.1 |
| 11 | John | 127.0.0.1 |
| 12 | Pit | 127.1.1.1 |
| 13 | Pit | 127.1.1.1 |
| 14 | Pit | 127.1.1.1 |
| 15 | Pit | 127.1.1.1 |
| 16 | Pit | 127.1.1.1 |
| 17 | Pit | 127.1.1.1 |
+----+-----------+----------------+
所以我想找到任何值都重复了 ip 在更好的情况下我想找到唯一值所以通过这个查询我可以找到它:
SELECT distinct `username`, `ip` FROM `logs`
现在查询结果是
+----+-----------+----------------+
| id | username | ip |
+----+-----------+----------------+
| 1 | John | 127.0.0.1 |
| 7 | John | 127.0.0.2 |
| 8 | John | 127.0.0.3 |
| 12 | Pit | 127.1.1.1 |
+----+-----------+----------------+
这很好,但我真正想要的是什么?我想找到任何用户名有重复的 ip 所以结果必须:
+----+-----------+----------------+
| id | username | ip |
+----+-----------+----------------+
| 1 | John | 127.0.0.1 |
| 7 | John | 127.0.0.2 |
| 8 | John | 127.0.0.3 |
+----+-----------+----------------+
因为那里的坑没有重复的 ip 我怎样才能从结果中删除坑?