table
name ip
one 127.0.0.1
one 127.0.0.1
one 127.0.0.2
two 127.0.0.1
two 127.0.0.2
two 127.0.0.2
如何才能查到
name count
one 2
two 2
one 与two 实际上都只有两个IP访问
create table tbllog ( [name] varchar(50), ip varchar(20) ) insert into tbllog select 'one','127.0.0.1' union all select 'one','127.0.0.1' union all select 'one','127.0.0.2' union all select 'two','127.0.0.1' union all select 'two','127.0.0.2' union all select 'two','127.0.0.2' select [name],count(distinct ip) from tbllog as a group by [name]