任务是这样的,从mysql中三个表中查询出相关联的数据,然后写入到csv文件里,形成报表,程序我写好了,但是碰到数据量的问题,account表里有60000条记录要读出来,相对应的其它两个表里order和quotation表里也同样有60000的数据,关联嘛。
我的水平只能写到一般数据量,这个数据量我写出来的程序实在吃不消,提示运行超时。Maximum execution time of 60 seconds exceeded,我也修改了运行时间,同样也是卡死,是不是php就不适合做这些处理? 望高手指教一番,互相讨教。要我贴码的话直说。
我的水平只能写到一般数据量,这个数据量我写出来的程序实在吃不消,提示运行超时。Maximum execution time of 60 seconds exceeded,我也修改了运行时间,同样也是卡死,是不是php就不适合做这些处理? 望高手指教一番,互相讨教。要我贴码的话直说。
while($arr=mysql_fetch_array($sql)){ $qarr=array();
$tarr=array();
$oarr=array();
$yarr=array(); $acc_no=$arr['acc_no'];
$state=$arr['state'];
$country=$arr['country'];
$institution=$arr['institution'];
//last quote date
$qsql=mysql_query("select max(init_date) as maxvalue from quotation where acc_no='$acc_no'");
$qarr=mysql_fetch_array($qsql);
$lastQuoteDate=$qarr['maxvalue'];
//total quote value
$tsql=mysql_query("select sum(amount) as total from quotation where acc_no='$acc_no'");
$tarr=mysql_fetch_array($tsql);
$totalQuoteValue=$tarr['total'];
//last order date
$osql=mysql_query("select max(order_date) as maxvalue2 from order_main where acc_no='$acc_no'");
$oarr=mysql_fetch_array($osql);
$lastOrderDate=$oarr['maxvalue2'];
//total order value
$ysql=mysql_query("select sum(total_price) as total2 from order_main where acc_no='$acc_no'");
$yarr=mysql_fetch_array($ysql);
$totalOrderValue=$yarr['total2'];//print_r($totalOrderValue);die();
/*
//EXCEL_OUT*/
$EXCEL_OUT.="$acc_no,$country,$state,$institution,$lastQuoteDate,$totalQuoteValue,$lastOrderDate,$totalOrderValue\n";
//print_r($EXCEL_OUT);die();
}
from account a,
(select acc_no, max(init_date) as maxvalue, sum(amount) as total from quotation group by acc_no) b,
(select acc_no, max(order_date) as maxvalue2, sum(total_price) as total2 from order_main group by acc_no) c
where a.acc_no=b.acc_no and a.acc_no=c.acc_no and a.acc_no>20000执行后循环读出即可
如在
quotation.init_date
quotation.amount
order_main.order_date
order_main.total_price
上建立索引,则速度还要快
Acc_no Acc_no Acc_no Acc_no Acc_no Acc_no Acc_no Acc_no
23364 USA NJ Merck & Co. Inc. 2010-8-13 5:38 6828.77 2010-8-18 2:02 6033.13
Acc_no Country State/Province Institution Last Quote Date Total Quote Value Last Order Date Total Order Value
23364 USA NJ Merck & Co. Inc. 2010-8-13 5:38 6828.77 2010-8-18 2:02 6033.13
23364,USA,NJ,Merck & Co., Inc.,2010-8-13 5:38,6828.77,2010-8-18 2:02,6033.13