本人有一个表:s_exp_shpping
本人想找出批次号 + 收件人名称 + 地址 + 电话都一样,并且最少出现过两次的记录,本人用下面方法运行时用了7s,有没有办法更快点?
select t.BATCH_NUM, t.name, t.SHPPING_ADDRESS, t.PHONE_NUMBER from s_exp_shpping t
where ((t.PARENT_SHPPING_ID = 0 and t.IS_SPLIT = 1)
or (t.PARENT_SHPPING_ID = 0 and t.IS_SPLIT = 2 and t.combine_flag = 1))
group by (CONCAT(t.BATCH_NUM, t.name, t.SHPPING_ADDRESS, t.PHONE_NUMBER))
having (count(CONCAT(t.BATCH_NUM, t.name, t.SHPPING_ADDRESS,t.PHONE_NUMBER))) > 1
在线等
本人想找出批次号 + 收件人名称 + 地址 + 电话都一样,并且最少出现过两次的记录,本人用下面方法运行时用了7s,有没有办法更快点?
select t.BATCH_NUM, t.name, t.SHPPING_ADDRESS, t.PHONE_NUMBER from s_exp_shpping t
where ((t.PARENT_SHPPING_ID = 0 and t.IS_SPLIT = 1)
or (t.PARENT_SHPPING_ID = 0 and t.IS_SPLIT = 2 and t.combine_flag = 1))
group by (CONCAT(t.BATCH_NUM, t.name, t.SHPPING_ADDRESS, t.PHONE_NUMBER))
having (count(CONCAT(t.BATCH_NUM, t.name, t.SHPPING_ADDRESS,t.PHONE_NUMBER))) > 1
在线等
解决方案
10
这样呢:
SELECT t.BATCH_NUM , t.name , t.SHPPING_ADDRESS , t.PHONE_NUMBER FROM s_exp_shpping t WHERE ( ( t.PARENT_SHPPING_ID = 0 AND t.IS_SPLIT = 1 ) OR ( t.PARENT_SHPPING_ID = 0 AND t.IS_SPLIT = 2 AND t.combine_flag = 1 ) ) GROUP BY t.BATCH_NUM, t.name, t.SHPPING_ADDRESS, t.PHONE_NUMBER HAVING count(*) > 1
30
用下楼上的,explain下,show index
10
以文本方式贴出
explain select …
show index from ..
以供分析。
explain select …
show index from ..
以供分析。