MySQL字符串操作

用户名

我有一个列中列出了一堆IP地址的数据库。我想计算每次出现IP地址的次数。但是我想删除IP地址中最后一个句点之后的所有数字,并按结果分组。因此,对于一个IP地址,例如192.178.168.2,我想按分组192.178.168同样,192.178.168.234将按分组192.178.168

我该如何处理这种类型的字符串?

select count(*)
from tbl t
group by t.ip_address
order by count(*) desc
limit 10
;
戈登·利诺夫

由于该功能,在MySQL中这真的很容易substring_index()

select substring_index(t.ip_address, '.', 3) as TypeC, count(*)
from tbl t
group by substring_index(t.ip_address, '.', 3)
order by count(*) desc
limit 10;

这不包括最后期限。如果您确实需要,请重新连接它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章