PHP MYSQL LOOP(插入TABLE_C)FROM QUERY RESULT TABLE_A和TABLE_B

时间:2014-02-25 17:46:57

标签: php mysql sql insert while-loop

我有3个表table_a(4000行)和table_b(35000行)和table_c来存储结果, 它需要670秒才能完成....,还有另一种方法可以做到这一点..?,(我也尝试左连接,但是右表给出的结果不止一个,左边的结果变得不止一个,而且它大约需要300秒才能完成......

autocommit = 0

$c_mgp = "select * from table_a where .......";
$c_mgp_r = mysqli_query($con_a,$c_mgp) or die (mysqli_error($con_a));
$multi_sq = '';
    $r = 0;
while($c_mgp_f = mysqli_fetch_array($c_mgp_r)) {
    $r++;
    $mgpstat = trim($c_mgp_f['STATUS']);
    $mgpval= trim($c_mgp_f['VAL']);
            $sand = trim(($c_mgp_f['SAND']);

$multi_sq .= "insert into table_c (NAME,VAL,VAL_RES) values('$mgpstat','$mgpval',
                  (select SUM(VAL_RES) from table_b where DATE = '$date_a' and GRUP = '$grup' and ACNO= '$sand'));" //this part is the most important thing, $sand always different (and always more than one row in result) each loop
if($r == 500){
    mysqli_multi_query...........;
    $r=0;
    $multi_sq='';
    }

  }

提交

非常感谢你的帮助...

0 个答案:

没有答案