PHPmodel查询数据库

在model层查询了数据库,我擦的时候是根据时间查询,应该出现每个时间下都有不同的数据,
但是在model层里查出来是查询出了所有的数据
这是model层:

class modelData{
public function change($tableName) {
    $sqlGetAllCode=sprintf("select distinct time from %s",$tableName);
        $codeArr=DB::select($sqlGetAllCode);
        $A_data = [];
        foreach ($codeArr as $a => $b) { //a是角标  b是对应的code编号
            $sqlGetData = sprintf("select `cumulative`from ".$tableName." ");
            $codeData = DB::select($sqlGetData);
         $A_data[$b->time]=[];
            foreach ($codeData as $m => $n) { //m角标  n->cumulative是值
                array_push($A_data[$b->time], $n->cumulative);  

        }
         }   
dd($A_data);
        return $A_data;
    }          
}

这是根据model层查出来的数据:

img

第7行sql 改为"select cumulativefrom ".$tableName." where time= '".$b->time."'"