码迷,mamicode.com
首页 > 其他好文 > 详细

筛选重复数据的方法

时间:2014-10-24 17:58:19      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:ar   sp   数据   on   bs   ef   as   sql   res   

//跟据帐号来查询出重复的订单
$sql_accounts = ‘select `wish_account` from wish_accounts where t_id=0‘;
$res = mysql_query($sql_accounts);
while($row = mysql_fetch_array($res)){

//这个跟据卖家id(其实就是一个唯一值)来筛选出重复的数据。
$sql = "SELECT count(0) as num,erp_orders_id,buyer_id,sales_account,orders_export_time
FROM erp_orders
WHERE sales_account=‘".$row[‘wish_account‘]."‘
AND orders_export_time>‘".date(‘Y-m-d H:i:s‘,time()-86400*3)."‘
AND orders_status in (1,3)
AND orders_total>0
GROUP BY sales_account,buyer_id
HAVING num>1
ORDER BY erp_orders_id ASC";
echo $sql."\n";
echo "<br />";
$result=mysql_query($sql);

 

 


//print_r($result);exit;

 

//跟据上面的重复的数据,我们又在筛选出重复数据中的那些重复数据。
while($order_list=mysql_fetch_array($result)){
$sql = "SELECT erp_orders_id,buyer_id,orders_type,sales_account,orders_export_time
FROM erp_orders
WHERE sales_account=‘".$order_list[‘sales_account‘]."‘
AND buyer_id=‘".$order_list[‘buyer_id‘]."‘
AND orders_export_time>‘".date(‘Y-m-d H:i:s‘,time()-86400*3)."‘
AND orders_status in(1,3)
AND orders_total>0
ORDER BY erp_orders_id ASC";
echo $sql."\n";
echo "<br />";

$_result=mysql_query($sql);
/*过滤第一条*/
mysql_fetch_array($_result);
while($order_list_temp=mysql_fetch_array($_result)){
echo "-----------------------------------------------\n";
echo "erp_orders_id:".$order_list_temp[‘erp_orders_id‘].
" orders_type:".$order_list_temp[‘orders_type‘].
" buyer_id:".$order_list_temp[‘buyer_id‘];
echo "\n";
// $sql="update erp_orders set orders_type=-1,buyer_id=‘".$order_list_temp[‘buyer_id‘].
// "_del‘ where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘";
// $sql ="delete from erp_orders where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
// echo $sql."\n";
// mysql_query($sql);
// $sql_products = "delete from erp_orders_products where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
// mysql_query($sql_products);
// echo $sql_products."\n";
$sql ="DELETE erp_orders,erp_orders_products FROM erp_orders LEFT JOIN erp_orders_products ON erp_orders.erp_orders_id = erp_orders_products.erp_orders_id WHERE erp_orders.erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
echo $sql."\n";exit;
mysql_query($sql);
echo "-----------------------------------------------\n";
}
}
}

筛选重复数据的方法

标签:ar   sp   数据   on   bs   ef   as   sql   res   

原文地址:http://www.cnblogs.com/kobigood/p/4048524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!