以表中某字段中部分字符做为分组依据
下面以ORM为例演示:
$result = $this->model->query()
->selectRaw('date_format(field_a, "%Y") as date, count(id) as count')
->groupBy('date')
->pluck('count', 'date')
->toArray();
$years = [];
foreach($result as $key=>$val) {
$years['year'][] = $key. ' 学年';
$years['datas'][] = $val;
}