SELECT b.id,a.姓名,a.手机
FROM 
(
  SELECT  COUNT([手机]) AS 记录数目,
          [姓名],[手机] 
  FROM tb_被访问者  
   GROUP BY [姓名],[手机]
  HAVING COUNT(手机)>1 
) AS a
 JOIN tb_被访问者 AS b
ON a.姓名=b.姓名
  AND a.手机=b.手机;

解决方案 »

  1.   


    select a.* from tb_被访问者 a,
    (select  ([姓名]),[手机] from tb_被访问者 group by [姓名],[手机] having count(手机)>1) b 
    where a.姓名=b.姓名 and a.手机=b.手机
      

  2.   

    就是用INNER JOIN(内连接)把表和你的结果集关联起来
    因为你的结果集无法显示ID这列,因此必须与源表关联,然后才能显示,就这意思。
      

  3.   

    declare @t table([id] int ,  [姓名] varchar(10),  [手机] int) 
    insert @t select 1,      '小明',    1234567 
    insert @t select 2,      '小红',    5555555 
    insert @t select 3,      '小明',    1234567 
    --首先找到重复的记录
    select  count([手机]) as 记录数目,([姓名]),[手机] from @t  group by [姓名],[手机] having count(手机)>1
    /*结果如下:
    记录数目        姓名         手机          
    ----------- ---------- ----------- 
    2           小明         1234567
    */
    --然后与原表关联 条件是姓名与手机全部相同 on t.[姓名]=s.[姓名] and t.[手机]=s.[手机]
    select t.* from @t t inner join 
      (select  count([手机]) as 记录数目,([姓名]),[手机] from @t  group by [姓名],[手机] having count(手机)>1) s 
      on t.[姓名]=s.[姓名] and t.[手机]=s.[手机]/*
    记录数目        姓名         手机          
    ----------- ---------- ----------- 
    2           小明         1234567(所影响的行数为 1 行)id          姓名         手机          
    ----------- ---------- ----------- 
    1           小明         1234567
    3           小明         1234567(所影响的行数为 2 行)
    */
      

  4.   

    --> --> (Andy)生成测试数据 2008-10-12
    Set Nocount On
    declare @1 table([id] int,[姓名] nvarchar(2),[手机] int)
    Insert @1
    select 1,N'小明',1234567 union all
    select 2,N'小红',5555555 union all
    select 3,N'小明',1234567
     
    Select * from @1 a Where Exists(Select 1 From @1 Where [手机]=a.[手机] And id<>a.id)/*
    id          姓名   手机
    ----------- ---- -----------
    1           小明   1234567
    3           小明   1234567
    */
      

  5.   

    declare @t table([id] int ,  [姓名] varchar(10),  [手机] int) 
    insert @t select 1,      '小明',    1234567 
    insert @t select 2,      '小红',    5555555 
    insert @t select 3,      '小明',    1234567 
    select *
    from @t a
    where (select count(1) from @t where a.[手机] = [手机]) > 1
    id          姓名         手机
    ----------- ---------- -----------
    1           小明         1234567
    3           小明         1234567(2 行受影响)