--> 测试数据: #T
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (IP varchar(13),c2 int)
insert into #T
select '192.168.0.1',1 union all
select '192.168.0.106',1 union all
select '192.168.1.116',1 union all
select '192.168.2.116',1 union all
select '61.125.137.5',1 union all
select '61.125.1.5',1
go
select left(IP,charindex('.',IP,charindex('.',IP)+1))+'*.*',count(*) cnt
from #T
group by left(IP,charindex('.',IP,charindex('.',IP)+1))+'*.*'
go
drop table #T
/*
cnt
---------------- -----------
192.168.*.* 4
61.125.*.* 2
(所影响的行数为 2 行)
*/