如何按一天中的时间对网站上的“注册”进行分组?
我已经尝试过了,但它不起作用。
$regs = DB::table('registrations')
->select('createddatetime', DB::raw('COUNT(id)'))
->groupBy(DB::raw('DATEPART(hour, createddatetime)'), 'createddatetime')
->get();
我收到错误:
无法访问空属性。
我预计查询结果将超过 0 个。
您可以使用 GroupBy 函数使其正确
$regs = DB::table('registrations')->select('createddatetime', DB::raw('COUNT(id) as count'))->get();
$regs = $regs->groupBy(function($reg){
return date('H',strtotime($reg->createddatetime));
});
echo '<pre>';
print_r($regs);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)