我有一个脚本,它上传 CSV 并在重复检查器临时表中插入数据库。此时,它执行以下操作:
1)检查自己(临时表)是否有重复项,将它们全部从临时表中删除 2)检查客户表是否有重复项,将它们从临时表中删除
现在我正在使用 php 循环来执行此操作,这似乎将整个事情拖到了停止状态,因为客户表有数十万条记录。我相信,如果我可以将很多内容放入查询中,它可能会使事情变得更好。上传工作正常,这是有问题的代码部分。
<?
// look for duplicate account_no in the temp table
$sql_1 = "SELECT account_no,count(*) FROM tempTable GROUP BY account_no";
$result_1 = mysql_query($sql_1) or die("Error: " . mysql_error() . "<br>");
while(list($acct,$numcount) = mysql_fetch_row($result_1)) {
// if there is a duplicate in tempTable, delete them all
if($numcount>1) {
$toBeRemoved+=$numcount;
$sql_delete = "DELETE FROM tempTable WHERE(account_no = '$acct')";
$result_delete = mysql_query($sql_delete) or die("Error: " . mysql_error() . "<br>");
}
}
// look for duplicate account_no in the customersTable and delete from tempTable
$sql_2 = "SELECT account_no FROM customersTable";
$result_2 = mysql_query($sql_2) or die("Error: " . mysql_error() . "<br>");
while(list($acct) = mysql_fetch_row($result_2)) {
$sql_delete = "DELETE FROM tempTable WHERE(account_no = '$acct')";
$result_delete = mysql_query($sql_delete) or die("Error: " . mysql_error() . "<br>");
}
?>