通过group by和having去除重复

$sql="SELECT peisonghao FROM ecs_order_info_ly GROUP BY peisonghao HAVING COUNT(*) >1";

$rlt=$GLOBALS['db']->query($sql);

while($data=$GLOBALS['db']->fetch_array($rlt)){

$rand=rand(10000,10000000);

$sql="update ecs_order_info_ly set order_sn='$rand' where order_id=".$data['order_id'];

$GLOBALS['db']->query($sql);

}

SELECT peisonghao FROM ecs_order_info_ly GROUP BY peisonghao HAVING COUNT(*) >1 把重复的行选出来

原文地址:https://www.cnblogs.com/microtiger/p/6208077.html