不好意思 没说清楚
再说一遍这个字段就是个手机号   插入数据的时候  有很多是重复的  我也不能一个
一个的找  所以想用一个sql语句把所有相同的找出来  当然是最少有两个
是一样的了  急啊 !!!!!!!!!   大侠们  

解决方案 »

  1.   

    我理解你的意思是说,你想知道你插入了多少个手机号,且分必是哪些号
    对不
    如果是这样直接
    select 手机号 from 表名 group by 手机号
    就可以得出已经插入的所有手机号
      

  2.   

    那你再查一个唯一的字段加在后面select 唯一字段,手机号 from 表名 group by 唯一字段,手机号如果还要查其它字段直接加在后面就行了,注意的是,select后面增加字段的时候
    group by 后面也要跟着加
      

  3.   

    很慢的方法
    select a.手机号 from 表名 a,表名 b where a.手机号 = b.手机号 and a.唯一字段 <> b.唯一字段
      

  4.   

    select (case when count(手机号)>1 then 手机号 else null end)as 手机号 from 表名 group by 手机号这样总可以了吧,只有是重复了的就有值,值为NULL的就是没有重复的如果你还想看倒底重复了几次select (case when count(手机号)>1 then 手机号 else null end)as 手机号,
           (case when count(手机号)>1 then count(手机号) else null end)as 手机号重复次数
    from 表名 group by 手机号
      

  5.   

    select (case when count(手机号) >1 then 手机号 else null end)as 手机号, 
           (case when count(手机号) >1 then count(手机号) else null end)as 手机号重复次数 
    from 表名 group by 手机号
    这个能找出重复的次数  但是我想把每条重复的数据都列出来
    想这样:id     name      cellphone         ..........
    1       aa       13526845954       ..........
    67      cc       13526845954       ............
    1107    mm       13879563214       .........
    757     uu       13879563214       .........
    382     uu       13879563214       .........类似于这样的
    不知道我说的 是否明白
      

  6.   

    select 手机号,* from 表名
    where  手机号 in (
                        select (case when count(手机号) >1 then 手机号 else null end)as 手机号 from 
                        表名 group by 手机号 
                       )
    order by 手机号
      

  7.   

    select * from users where cellphone in(select(case when count(cellphone)>1 then cellphone else null end) as cellphone from users group by cellphone) order by cellphone
      

  8.   

    users  表名
    cellphone  是字段名
      

  9.   

    除非是亲自在你的数据库上搞,不然我也不知道是什么原因了
    重复率高的字段和低的字段都都在我这边试过了,最慢的时候不会大于8秒如果把select * 改为单个字段会把时间从七秒多,降为一秒多你是不是表的字段特别多
    我的表有27个字段但是只要查上五六个就可比全部查快不了多少了
      

  10.   

    select cellphone,id,name from users where cellphone 
    in(
         select cellphone 
         from(
              select(case when count(cellphone) >1 then cellphone else 0 end) as cellphone 
              from users group by cellphone
             ) t
    where cellphone <>0 
    order by cellphone用成这个试试看
      

  11.   

    有错误啊  SQL 查询: SELECT cellphone
    FROM users
    WHERE cellphone
    IN (
    SELECT cellphone
    FROM (SELECT (CASE WHEN count( cellphone ) >1
    THEN cellphone
    ELSE 0 
    END 
    ) AS cellphone
    FROM users
    GROUP BY cellphone
    )t
    WHERE cellphone !=0
    ORDER BY cellphone
    LIMIT 0 , 30 MySQL 返回: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 
      

  12.   

    不好意思,
    cellphone !=0后面写掉了半边括号
      

  13.   

    好像还是那样 我是在 phpmyadmin 里直接执行的 sql 语句  
      

  14.   

    select count(phone) as a,phone
    from table 
    group by phone 
    having(count(phone))>1