May I ask you how PHP optimizes foreach with sql?

foreach ($res ["xsumpre"] as $key = > $value) {

        $fsql="select count(*) from (SELECT sum(sumprem)  FROM datatom.fccont where 

signdate BETWEEN"$stime" AND"$etime" AND
agentcode in (select agentcode from datatom.shouxian_faagenttree
where agentstate not in ("01 charge charge 02") and OUTWORKDATE between"$stime" AND"$etime")
GROUP BY agentcode having sum (sumprem) < ="$value" ORDER BY sum) as a ";

        $fres=$this->pgdb->mpg_select($fsql)["0"]["count"];
        // var_dump($value,$fres["0"]["count"]);
        $res["tate"][]=round($fres/$zres["0"]["count"],4)*100;
    }
    return $res;-sharp-sharp-sharp 

the environmental background of the problems and what methods you have tried

the interface is slow

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

the number of xsumpre is the same as the number of tate
{

"code": 0,
"data": {
    "xsumpre": [
        1001066,
        2002132,
        3003198,
        4004264,
        5005330,
        6006396,
        7007462,
        8008528,
        9009594,
        10010660
    ],
    "quit": 12.21,
    "tate": [
        0.46,
        0.46,
        0.46,
        0.46,
        0.46,
        0.46,
        0.46,
        0.46,
        0.46,
        0.46
    ]
},
"msg": "success"

}

Oct.06,2021

query with tables

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5aab0-455c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5aab0-455c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?