我理解你的意思是说,你想知道你插入了多少个手机号,且分必是哪些号 对不 如果是这样直接 select 手机号 from 表名 group by 手机号 就可以得出已经插入的所有手机号
那你再查一个唯一的字段加在后面select 唯一字段,手机号 from 表名 group by 唯一字段,手机号如果还要查其它字段直接加在后面就行了,注意的是,select后面增加字段的时候 group by 后面也要跟着加
很慢的方法 select a.手机号 from 表名 a,表名 b where a.手机号 = b.手机号 and a.唯一字段 <> b.唯一字段
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 手机号
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 .........类似于这样的 不知道我说的 是否明白
select 手机号,* from 表名 where 手机号 in ( select (case when count(手机号) >1 then 手机号 else null end)as 手机号 from 表名 group by 手机号 ) order by 手机号
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
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用成这个试试看
有错误啊 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
不好意思, cellphone !=0后面写掉了半边括号
好像还是那样 我是在 phpmyadmin 里直接执行的 sql 语句
select count(phone) as a,phone from table group by phone having(count(phone))>1
对不
如果是这样直接
select 手机号 from 表名 group by 手机号
就可以得出已经插入的所有手机号
group by 后面也要跟着加
select a.手机号 from 表名 a,表名 b where a.手机号 = b.手机号 and a.唯一字段 <> b.唯一字段
(case when count(手机号)>1 then count(手机号) else null end)as 手机号重复次数
from 表名 group by 手机号
(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 .........类似于这样的
不知道我说的 是否明白
where 手机号 in (
select (case when count(手机号) >1 then 手机号 else null end)as 手机号 from
表名 group by 手机号
)
order by 手机号
cellphone 是字段名
重复率高的字段和低的字段都都在我这边试过了,最慢的时候不会大于8秒如果把select * 改为单个字段会把时间从七秒多,降为一秒多你是不是表的字段特别多
我的表有27个字段但是只要查上五六个就可比全部查快不了多少了
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用成这个试试看
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
cellphone !=0后面写掉了半边括号
from table
group by phone
having(count(phone))>1