我想从数据库中选择相同的单词,如
Database Name: username
====================================================
| id | name | fathername | ip | datetime |
| 1 | Ali | Imran |192.168.1.1 | 12-12-2015|
| 2 | Asd | hafiz |142.150.8.9 | 12-12-2015|
| 3 | Sef | warya |100.178.3.7 | 12-12-2015|
| 4 | Qasim | zaheer |192.168.1.1 | 12-12-2015|
| 5 | Zulfi | Zahid |192.168.1.1 | 12-12-2015|
| 6 | Jamel | Hasan |192.168.1.1 | 12-12-2015|
| 7 | Wasif | Junaid |192.168.1.1 | 12-12-2015|
====================================================
当我使用计数器时(选择Count(*)作为数字From ......)然后结果echo是(7)我想选择与一个ip相同的ip。喜欢(ID:1,4,5,6,7)5是同一个ip我想显示这5个相同的ip作为1个IP总记录-3
答案 0 :(得分:1)
SELECT count(*) FROM `username` GROUP BY `ip`;
或
SELECT DISTINCT(`ip`) FROM `username`;
或
SELECT count(*) FROM `username` WHERE `ip` IN (SELECT DISTINCT(`ip`) FROM `username`) ;
答案 1 :(得分:0)
SELECT count(*) FROM `username` GROUP BY `ip`;
这就是你想要的吗?如果没有,你能把你想要的模式放在哪里吗?
答案 2 :(得分:0)
在sql中,
SELECT COUNT(*) FROM `tbl` WHERE `ip` = '192.168.1.1'
你也可以使用php while循环遍历每个查询:
SELECT DISINCT(`ip`) FROM `tbl`