我需要按子網(前3個八位字節)對IP列表進行分組來計數。舉例來說,如果我有Ips的如何在MySQL中通過子網對IP列表進行分組?
123.12.12.12
123.12.12.11
123.12.11.11
我一定要得到這樣的結果:
123.12.12 | 2
123.12.11 | 1
我GOOGLE了這個expample:
select
substr(ip,1,locate('.',ip,locate('.',ip)+1)-1)
as ip, count(ip) as count
from ip_list
group by ip ORDER BY count DESC
但組的列表只有兩個字節。我在所有這些locate(locate(locate(...)))
中都輸了。有人可以幫助修改這個來獲得正確的結果嗎?
123.0.0.0是A類,所以(默認)子網掩碼是255.0.0.0,而不是255.255.255.0 –